jnp102,
One of the challenges is that identifying the user can vary. The following works for me using Windows 2000 with user identification based on their login entry.
I'm thinking it will work for you, too, but that's my disclaimer.
In general, this database has a primary startup form with buttons to select other forms. I use logic to make the buttons visible/invisible depending on access to be allowed.
Hope this provides some help,
Bob
I have a table, MgrTB_tlkpPrivileges, that contains selected users who are to have access to specific forms that others cannot. The structure is:
PrivID - Autonumber ID field
SignOn - User's Windows sign on entry
LastName - For User identification
FirstName - Ditto
AllowHR - True/False (yes/no,boolean) indicates whether User has HR access
AllowExitInterview - True/False indicates if User can look at exit interviews
Following are global variables. (They're not required, but might be useful for later development):
'FOLLOWING USED TO LIMIT ACCESS TO SELECTED OBJECTS
'THESE ARE SET WHEN frm_MAIN is loaded using the table tlkpPrivileges
Public pblnHR As Variant 'T/F-Allow use of HR forms.
Public pblnExitInterview As Variant 'T/F-Allow use of the Exit Interview form.
Following is code triggered by the On Load event for the main (startup) form:
TABLE VALUES ARE 0 (FALSE) OR 1 (TRUE). NO MATCH RETURNS NULL
pblnHR = DLookup("[AllowHR]", "MgrTB_tlkpPrivileges", "SignOn = '" & User & "'")
pblnExitInterview = DLookup("[AllowExitInterview]", "MgrTB_tlkpPrivileges", "SignOn = '" & User & "'")
'IF HR MENU ACCESS NOT ALLOWED, MAKE BUTTON INVISIBLE
If Nz(pblnHR) = 0 Then
Me.cmd_HR_Functions.Visible = False
Else
Me.cmd_HR_Functions.Visible = True
End If
'IF EXIT INTERVIEW ACCESS NOT ALLOWED, MAKE BUTTON INVISIBLE
If Nz(pblnExitInterview) = 0 Then
Me.[Exit Interview].Visible = False
Else
Me.[Exit Interview].Visible = True
End If
Separate module used to identify the User. We include this in all new databases. That's why the global variables are listed separately. (If that makes any sense at all.)
Option Compare Database
Option Explicit
'Declare APIs
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Declare Function GetComputerName Lib "kernel32.dll" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Function User() As String
'------------------------------------------------------------------------
' Determines current NT user using a SQL call
' 10/23/02
'
' Returns the current NT user name
'
' Usage:
' stUser = User
'------------------------------------------------------------------------
On Error GoTo Err_User
' Display the name of the user currently logged on.
Dim stUser As String
Dim intLength As Long
Dim intDummy As Long
stUser = Space(50)
intLength = 50
intDummy = GetUserName(stUser, intLength)
User = Left(stUser, intLength - 1)
'FOLLOWING ADDED TO IDENTIFY AND STORE THE CURRENT USER NAME
UserName = Left(stUser, InStr(stUser, Chr(0)) - 1)
Exit_User:
Exit Function
Err_User:
Select Case Err.Number
Case Else
End Select
Resume Exit_User
End Function