Capture User group log in

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a DB using the User-Security Level which has just 3 groups. The
SuperAdmin, the RegAdmin, and the normal user. Currently when the program
starts up I have it set to display a form, which is hidden and runs some
procedures. However, it now needs to be changed to determine which group the
user belongs to when signing in. From the log-in I need to display a
separate form. For instance the RegAdmin needs to have a maintenance form
appear first, which the normal user will not have access to. How do I
capture which group the person signed as and then use this info to determine
which form is displayed first in the Starup under tools?

Thanks
 
Ok I am confused. I read and re-read the information, but I am still
uncertain on how to invoke this. All I am trying to do is caputure the
log-in user name. Then when the program opens a hidden form will check to
see if they belong to this group, if so run this procedure and open this form
else run this other procedure and open a different form.
I saw this in one of the messages here and modified a little.


' Function: isMemberOfGrp( )
' Returns True if the user is in the group.
' Usage: isMemberOfGrp(CurrentUser(), "Admins")
'=======================================

Public Function isMemberOfGrp(sUserName As String, sGrpName As String)

On Error Resume Next

Dim memID As String

memID = DBEngine(0).Users(sUserName).Groups(sGrpName).Name

'-------------------------------------------------------------------
' Determine whether checking this Property
' caused an error or not.
'-------------------------------------------------------------------

If (Err.Number = 0) Then
isMemberOfGrp = True
Else
isMemberOfGrp = False
End If
End Function


Then onload event of the hidden form I have.

If isMemberOfGrp(CurrentUser(), "RegAdmin") Then
run this procedure blah blah
ElseIf isMemberOfGrp(CurrentUser(), "NormUser") Then
run this procedure blah blah
end if
 
in message:
Ok I am confused. I read and re-read the information, but I am still
uncertain on how to invoke this. All I am trying to do is caputure the
log-in user name. Then when the program opens a hidden form will check to
see if they belong to this group, if so run this procedure and open this form
else run this other procedure and open a different form.
I saw this in one of the messages here and modified a little.

This sounds like a good place to use an AutoExec macro.

1. Copy/paste this code into a standard module (just overwrite
the function already there:

' Function: IsMemberOfGrp( )
' Returns True if the user is in the group.
' Usage: isMemberOfGrp(CurrentUser(), "Admins")
'=======================================

Public Function IsMemberOfGrp(sUserName As String, sGrpName As String)

On Error Resume Next

Dim strMemID As String

strMemID = DBEngine(0).Users(sUserName).Groups(sGrpName).Name
'-------------------------------------------------------------------
' Determine whether checking this Property
' caused an error or not.
'-------------------------------------------------------------------
If (Err.Number = 0) Then
IsMemberOfGrp = True
Else
IsMemberOfGrp = False
End If

End Function

2. Copy/paste this code into the same module if you prefer:

Public Function ShowCorrectForm()
On Error GoTo ErrorPoint

If IsMemberOfGrp(CurrentUser(), "RegAdmin") = True Then
' Run this procedure blah blah
' Open admin form
' DoCmd.OpenForm "frmAdmins"
ElseIf IsMemberOfGrp(CurrentUser(), "NormUser") = True Then
' Run this procedure blah blah
' Open regular user form
' DoCmd.OpenForm "frmUsers"
End If

ExitPoint:
Exit Function

ErrorPoint:
MsgBox "The following error has occurred:" _
& vbNewLine & "Error Number: " & Err.Number _
& vbNewLine & "Error Description: " & Err.Description _
, vbExclamation, "Unexpected Error"
Resume ExitPoint

End Function

Adjust of course to run whatever you need it to.

3. Compile the code and save the module with a unique name
(basUtilities) or something.

4. Create a new macro. In the Action combo box select the option
called RunCode. in the Function name area near the bottom enter:
=ShowCorrectForm()

5. Save and close the macro with the name of Autoexec.
This will cause this code to run everytime the database starts,
unless of course you use the Shift key bypass.

Works just fine in my tests.
Hope that helps,
 
Sorry for the late reply. Thanks for the input, but I decided to include the
info on the hidden form on load event instead of a macro. I didn't have =
true part on the form which caused it not to work. Thanks again.
 
in message:
Sorry for the late reply. Thanks for the input, but I decided to include the
info on the hidden form on load event instead of a macro. I didn't have =
true part on the form which caused it not to work. Thanks again.

No problem, glad you have it working now.
 
Back
Top