Want to test user's security group membership in Access 
Author Message
 Want to test user's security group membership in Access

I have an Access (2002) app I hope to use for a chain of
small stores that each use a specific portion of the
records in a table (based on a partial key). I want to
test the logged in user's group membership to set a query
variable so forms show only the records for that group's
location, however I can find no information on how to
evaluate a user's identity.

Can anyone suggest object properties I can evaluate?



Wed, 14 Sep 2005 03:14:05 GMT  
 Want to test user's security group membership in Access
Try this from an early Access Developer's handbook
Call it by something like
If glrIsGroupMember("Admins") then
Etc

Function glrIsGroupMember(ByVal strGroup As String, _
 Optional ByVal varUser As Variant) As Boolean
    ' Verifies if a user is a member of a group.
    On Error GoTo glrIsGroupMemberErr

    Dim wrk As Workspace
    Dim usr As User
    Dim grp As Group
    Dim strMsg As String
    Dim intErrHndlrFlag As Integer
    Dim varGroupName As Variant

    Const glrcFlagSetUser = 1
    Const glrcFlagSetGroup = 2
    Const glrcFlagCheckMember = 4
    Const glrcFlagElse = 0

    Const glrcProcName = "glrIsGroupMember"

    glrIsGroupMember = False

    'Initialize flag for determining
    'context for error handler
    intErrHndlrFlag = glrcFlagElse

    Set wrk = DBEngine.Workspaces(0)
    'Refresh users and groups collections
    wrk.Users.Refresh
    wrk.Groups.Refresh

    If IsMissing(varUser) Then varUser = CurrentUser()

    intErrHndlrFlag = glrcFlagSetUser
    Set usr = wrk.Users(varUser)

    intErrHndlrFlag = glrcFlagSetGroup
    Set grp = wrk.Groups(strGroup)

    intErrHndlrFlag = glrcFlagCheckMember
    varGroupName = usr.Groups(strGroup).Name

    If Not IsEmpty(varGroupName) Then
        glrIsGroupMember = True
    End If

glrIsGroupMemberDone:
    On Error GoTo 0
    Exit Function

glrIsGroupMemberErr:
    Select Case Err
    Case 3265 ' glrcErrNameNotInCollection
        Select Case intErrHndlrFlag
        Case 1 ' glrcFlagSetUser
            strMsg = "The user account '" & varUser & _
             "' doesn't exist."
        Case 2 ' glrcFlagSetGroup
            strMsg = "The group account '" & strGroup & _
             "' doesn't exist."
        Case 4 ' glrcFlagCheckMember
            Resume Next
        Case Else
            strMsg = "Error " & Err.Number & ": " & _
             Err.Description
        End Select
   Case 3303 'glrcErrNoPermission
        strMsg = "You don't have permission to perform " &
_
         "this operation."

    Case Else
        strMsg = "Error " & Err.Number & ": " &
Err.Description
    End Select
        MsgBox strMsg, vbCritical + vbOKOnly, "Procedure "
& _
         glrcProcName
    Resume glrIsGroupMemberDone

End Function

Other one is the function CurrentUser(). Returns the
userID of the person logged on to Access

Both work on A97 and A2000 but havn't tried it on A2002

Good luck, Trev

Quote:
>-----Original Message-----
>I have an Access (2002) app I hope to use for a chain of
>small stores that each use a specific portion of the
>records in a table (based on a partial key). I want to
>test the logged in user's group membership to set a query
>variable so forms show only the records for that group's
>location, however I can find no information on how to
>evaluate a user's identity.

>Can anyone suggest object properties I can evaluate?

>.



Wed, 14 Sep 2005 05:30:41 GMT  
 Want to test user's security group membership in Access
Thanks, Trev. It looks like the code sample might have
been targeted for Access 97, as I can no longer find
reference to the "Workgroup", "User", and "Group" data
types in Access 2002. The CurrentUser() function might be
my only route, though I really need to test user group to
allow me to set conditions that apply to all staff of one
of twelve locations.

Quote:
>-----Original Message-----
>Try this from an early Access Developer's handbook
>Call it by something like
>If glrIsGroupMember("Admins") then
>Etc

>Function glrIsGroupMember(ByVal strGroup As String, _
> Optional ByVal varUser As Variant) As Boolean
>    ' Verifies if a user is a member of a group.
>    On Error GoTo glrIsGroupMemberErr

>    Dim wrk As Workspace
>    Dim usr As User
>    Dim grp As Group
>    Dim strMsg As String
>    Dim intErrHndlrFlag As Integer
>    Dim varGroupName As Variant

>    Const glrcFlagSetUser = 1
>    Const glrcFlagSetGroup = 2
>    Const glrcFlagCheckMember = 4
>    Const glrcFlagElse = 0

>    Const glrcProcName = "glrIsGroupMember"

>    glrIsGroupMember = False

>    'Initialize flag for determining
>    'context for error handler
>    intErrHndlrFlag = glrcFlagElse

>    Set wrk = DBEngine.Workspaces(0)
>    'Refresh users and groups collections
>    wrk.Users.Refresh
>    wrk.Groups.Refresh

>    If IsMissing(varUser) Then varUser = CurrentUser()

>    intErrHndlrFlag = glrcFlagSetUser
>    Set usr = wrk.Users(varUser)

>    intErrHndlrFlag = glrcFlagSetGroup
>    Set grp = wrk.Groups(strGroup)

>    intErrHndlrFlag = glrcFlagCheckMember
>    varGroupName = usr.Groups(strGroup).Name

>    If Not IsEmpty(varGroupName) Then
>        glrIsGroupMember = True
>    End If

>glrIsGroupMemberDone:
>    On Error GoTo 0
>    Exit Function

>glrIsGroupMemberErr:
>    Select Case Err
>    Case 3265 ' glrcErrNameNotInCollection
>        Select Case intErrHndlrFlag
>        Case 1 ' glrcFlagSetUser
>            strMsg = "The user account '" & varUser & _
>             "' doesn't exist."
>        Case 2 ' glrcFlagSetGroup
>            strMsg = "The group account '" & strGroup & _
>             "' doesn't exist."
>        Case 4 ' glrcFlagCheckMember
>            Resume Next
>        Case Else
>            strMsg = "Error " & Err.Number & ": " & _
>             Err.Description
>        End Select
>   Case 3303 'glrcErrNoPermission
>        strMsg = "You don't have permission to perform "
&
>_
>         "this operation."

>    Case Else
>        strMsg = "Error " & Err.Number & ": " &
>Err.Description
>    End Select
>        MsgBox strMsg, vbCritical +

vbOKOnly, "Procedure "

- Show quoted text -

Quote:
>& _
>         glrcProcName
>    Resume glrIsGroupMemberDone

>End Function

>Other one is the function CurrentUser(). Returns the
>userID of the person logged on to Access

>Both work on A97 and A2000 but havn't tried it on A2002

>Good luck, Trev

>>-----Original Message-----
>>I have an Access (2002) app I hope to use for a chain of
>>small stores that each use a specific portion of the
>>records in a table (based on a partial key). I want to
>>test the logged in user's group membership to set a
query
>>variable so forms show only the records for that group's
>>location, however I can find no information on how to
>>evaluate a user's identity.

>>Can anyone suggest object properties I can evaluate?

>>.

>.



Thu, 15 Sep 2005 23:42:34 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Testing for membership in NT Security Groups

2. Checking Group membership from low-security user accounts.

3. Get User's rights/group membership details

4. Retrieving group membership's of Novell user?

5. enumerating membership of groups by the user's token

6. Users' Group Membership

7. Get User's Group Memberships

8. How do I programatically modify a User's NT Group membership in VB

9. Users' Group Membership

10. Q:How do determine a user's NT group membership

11. How to check a user's NT group membership

12. How do I get the logged on user's NT Group membership

 

 
Powered by phpBB® Forum Software