John Colby
jwcolby at ColbyConsulting.com
Sun Apr 2 08:58:05 CDT 2006
Thanks for this. Another tool stored away in my framework.
:~)
John W. Colby
www.ColbyConsulting.com
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Stuart McLachlan
Sent: Sunday, April 02, 2006 6:49 AM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Record security
On 2 Apr 2006 at 6:19, John Eget wrote:
> In this database, each record entry has an individual field for name. I
> would like anyone to view another individuals records but I am trying
> to prevent another individual from editing or deleting a record that
> does not belong to them. Does someone have an example of a login
> process and then disabling a record from being deleted or edited by
another individual.
Here's how I would do it using the Windows login name:
Assuming that the field in the record is called "UserName"
1. Create a function in a module to read the Windows login name:
Option Compare Database 'Use database order for string comparisons
Option Explicit
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal
lpBuffer As String, nSize As Long) As Long Function Username() Dim strUname
As String * 32 Dim lngResponse As Long lngResponse = GetUserName(strUname,
32) If Len(strUname) > 1 Then
Username = Left$(strUname, InStr(strUname, Chr$(0)) - 1) Else
Username = "No logged In User"
End If
End Function
When the record is created, automatically fill the UserName field (a hidden
bound text box on the form with a default value of "=Username()"
will do it).
In the Form_Delete and Form_BeforeUpdate events include:
If Me.UserName <> Username() Then
Msgbox "You can't alter someone else's records"
Canel = True
Exit Sub
End If
--
Stuart
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com