MS Access VBA – List Of Security Groups a User Belongs To

The following function will return a listing of all of the Security Group the current user belongs to.

Function fncUserGroups() As String
On Error GoTo Error_Handler
' Created and provided by Dirk Goldgar (MS Access MVP)
' NOTE: Requires a reference to the DAO Object Library.
' PURPOSE: Returns a comma-separated list of the security groups of which
'          the current user is a member.

    Dim ws          As DAO.Workspace
    Dim grp         As DAO.Group
    Dim strGroups   As String

    Set ws = DBEngine.Workspaces(0)

    For Each grp In ws.Users(CurrentUser).Groups
        strGroups = strGroups & ", " & grp.Name
    Next grp

    fncUserGroups = Mid(strGroups, 3)

Error_Handler_Exit:
    On Error Resume Next
    Set ws = Nothing
    Exit Function

Error_Handler:
    MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf & "Error Number: " & _
    Err.Number & vbCrLf & "Error Source: fncUserGroups" & vbCrLf & "Error Description: " & _
    Err.Description, vbCritical, "An Error has Occurred!"
    Resume Error_Handler_Exit
End Function