| | |
|
|
|
User groups in VBA Code |
| message from Jim Franklin on 27 May 2004 |
Hi,
Can anyone tell me if it is possible to determine whether the current user
is a member of a particular user group by using code. I want to modify the
appearance of a form on opening, depending on whether the user is a member
of group xxxx.
Thanks as always for any help anyone can provide,
Jim F.
|
| Lynn Trapp replied to Jim Franklin on 27 May 2004 |
There is code in the Security FAQ to do that. Bear in mind that a given user
can be a member of more than one group.
|
| Allen Browne replied to Jim Franklin on 28 May 2004 |
Function IsUserInGroup(strUser As String, strGroup As String) As Boolean
'Returns True if the user is in the group.
'Example: IsUserInGroup(CurrentUser(), "Admins")
Dim wk As Workspace
Dim grx As Groups
Dim grp As Group
Dim usx As Users
Dim usr As User
Set grx = DBEngine(0).Groups
For Each grp In grx
If grp.Name = strGroup Then
Set usx = grp.Users
For Each usr In usx
If usr.Name = strUser Then
IsUserInGroup = True
Exit For
End If
Next
End If
Next
Set usr = Nothing
Set usx = Nothing
Set grp = Nothing
Set grx = Nothing
End Function
|
| Graham R Seach replied to Jim Franklin on 28 May 2004 |
Jim,
Public Function IsUserInGroup(sUser As String, sGroup As String) As Boolean
'Determines if a specific user belongs to a specific group
Dim sReturn As String
On Error Resume Next
Err.Clear
sReturn = DBEngine(0).Groups(sGroup).Users(sUser).Name
IsUserInGroup = (Err = 0)
End Function
You can determine the current username with:
DBEngine(0).UserName
So, you can call the above function like so:
If IsUserInGroup(DBEngine(0).UserName, "Admins") Then
'The user is a member of the Admins group.
End If
Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html
"Jim Franklin" <james.franklin@ntlworld.com> wrote in message
news:YWptc.122$yc4.43@newsfe5-win...
|
|
Archived message: User groups in VBA Code (MS Access Forms)