Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

referencing user groups in code

Status
Not open for further replies.

blue77

Technical User
Nov 1, 2001
11
GB
I'm trying to carry out a specific function that will only run if members from a particular user group log on to the database.
Does anyone know if there is a similar function to CurrentUser(), but one where an entire group of users can be referenced (eg Accounts), not just one user at a time (eg Joe Soap)?

Many thanks to the wizzards who always seem to come up with good answers to these kind of questions.

Nick
 
After much struggling with this problem myself, I came up with the following function (with a lot of help from various sources):
Code:
Public Function IsMember(strGroup As String, Optional strUserName As String = "") As Boolean

    IsMember = InStr(UserGroupList(strUserName), strGroup) <> 0
    
End Function

Private Function UserGroupList(Optional strUserName As String = &quot;&quot;) As String

    Dim ws As DAO.Workspace
    Dim usr As DAO.User
    Dim grp As DAO.Group
    
    If strUserName = &quot;&quot; Then strUserName = CurrentUser
    
    Set ws = DBEngine.Workspaces(0)
    Set usr = ws.Users(strUserName)
    
    For Each grp In usr.Groups
        If Len(UserGroupList) > 0 Then
            UserGroupList = UserGroupList + &quot;;&quot;
        End If
        UserGroupList = UserGroupList + grp.Name
    Next grp
    
    Set usr = Nothing
    Set grp = Nothing
    Set ws = Nothing
    
End Function
[code]
It's difficult to have a function like CurrentGroup because a user can belong to more than one group.  What you can do, though, is use [code]IsMember(&quot;users&quot;)
to determine whether or not the current user is a member of a certain group.

Hope this helps a little.

--Ryan
 
I'll have a go with that, Ryan.
I'm sure it will work.

Thanks a lot

Nick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top