I am building a switchboard in which I want main users have access only
to the main switchboard. How do I password my drill down button to
keep unwanted users from accessing lower switchboards? Thanks!
If you want to be more polite to the user and not temp them with buttons
that will return nasty messages telling them that they're not allowed to go
there, you could disable buttons based using code in the forms open event.
I just finished writing this simple function to check to see if a user is in
a specific group:
Public Function UserIsInGroup(strGroup As String) As Boolean
Dim wks As DAO.Workspace
Dim dbUser As DAO.User
Dim fRetVal As Boolean
On Error GoTo Err_UserIsInGroup
Set wks = DBEngine.Workspaces(0)
For Each dbUser In wks.Groups(strGroup).Users
If dbUser.Name = CurrentUser() Then
fRetVal = True
End If
Next
Exit_UserIsInGroup:
UserIsInGroup = fRetVal
Exit Function
Err_UserIsInGroup:
MsgBox "An unexpected error has ocurred when trying to determine if the
current " _
& "user '" & CurrentUser() & "' is in the group '" & strGroup &
"'.", vbInformation, "Unexpected Error"
fRetVal = False
Resume Exit_UserIsInGroup
End Function
In the open event of your main switchboard, you could call this function to
decide whether or not to enable a button.
cmdYourButton.Enabled = UserIsInGroup("Managers")
I think that should work but I haven't had much time to test it. Like I
said, I just wrote it. The timing of your question was amazing. I wrote this
function about 15 minutes ago to use at startup to determine which
switchboard form to open.
I hope this helps. I'm just learning some of this myself so if anyone finds
errors in my code or logic, please don't hesitate to point them out.