Identify Current Users Group

  • Thread starter Thread starter Don
  • Start date Start date
D

Don

I am trying to identify the current User's Group in order
to limit or deliver functionality based on this group. I
have tried to use the sample code in the FAQ doc, but
cannot seem to make it happen.

Can someone please tell me if there is a simple way to
identifty the Group that the current user is identified
with? Or please explain the code from the FAQs doc.

Thank you,
Don
 
It's not really possible to idenity the current user's group, since a user
can exist in more than one group. The best you can get is a list of all of
the groups to which a user exists, or a Yes/No as to whether or not they
belong to a particular group.

That's why section 22 of the FAQ has the two separate functions:

List Groups User is a member of:

Function faq_ListGroupsOfUser (strUserName As String)
Dim ws As WorkSpace
Dim usr As User
Dim i As Integer

Set ws = DBEngine.Workspaces(0)
Set usr = ws.Users(strUserName)
For i = 0 To usr.Groups.count - 1
Debug.Print usr.Groups(i).Name
Next i
End Function

Determine if a User is in a given Group:

Function faq_IsUserInGroup (strGroup As String, strUser as String) As
Integer
' Returns True if user is in group, False otherwise
' This only works if you're a member of the Admins group.
Dim ws As WorkSpace
Dim grp As Group
Dim strUserName as string

Set ws = DBEngine.Workspaces(0)
Set grp = ws.Groups(strGroup)
On Error Resume Next
strUserName = ws.groups(strGroup).users(strUser).Name
faq_IsUserInGroup = (Err = 0)
End Function
 
Thanks Doug.

-----Original Message-----
It's not really possible to idenity the current user's group, since a user
can exist in more than one group. The best you can get is a list of all of
the groups to which a user exists, or a Yes/No as to whether or not they
belong to a particular group.

That's why section 22 of the FAQ has the two separate functions:

List Groups User is a member of:

Function faq_ListGroupsOfUser (strUserName As String)
Dim ws As WorkSpace
Dim usr As User
Dim i As Integer

Set ws = DBEngine.Workspaces(0)
Set usr = ws.Users(strUserName)
For i = 0 To usr.Groups.count - 1
Debug.Print usr.Groups(i).Name
Next i
End Function

Determine if a User is in a given Group:

Function faq_IsUserInGroup (strGroup As String, strUser as String) As
Integer
' Returns True if user is in group, False otherwise
' This only works if you're a member of the Admins group.
Dim ws As WorkSpace
Dim grp As Group
Dim strUserName as string

Set ws = DBEngine.Workspaces(0)
Set grp = ws.Groups(strGroup)
On Error Resume Next
strUserName = ws.groups(strGroup).users(strUser).Name
faq_IsUserInGroup = (Err = 0)
End Function



--
Doug Steele, Microsoft Access MVP






.
 
Back
Top