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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking a Users Group membership 1

Status
Not open for further replies.

scottetombleson

Programmer
Jan 8, 2005
18
US
How do you check the current users group membership before an action? I can't find the code for this anywhere. Thanks in advance for any help.

Scott
 
Code:
Function GetCurrentUserGroups() As String
    Dim wrk As Workspace
    Dim usr As User
    Dim grp As Group
    Dim strGroups As String
    
    On Error Resume Next
    
    Set wrk = DBEngine.Workspaces(0)
    Set usr = wrk.Users(Application.CurrentUser)
    
    For Each grp In usr.Groups
      strGroups = strGroups & grp.Name & ","
    Next grp
    
    GetCurrentUserGroups = Left(strGroups, InStrRev(strGroups, ",") - 1)
    
End Function

VBSlammer
redinvader3walking.gif

"You just have to know which screws to turn." - Professor Bob
 
You can use the previous function along with this one to see if the current user is in a particular group:

Example:
[tt]
If InGroup("Admins") Then
[green]'allow admin task[/green]
End If[/tt]

Code:
Function InGroup(ByVal strGroup As String) As Boolean
  Dim varGroups As Variant
  Dim i As Integer

  varGroups = Split([blue]GetCurrentUserGroups()[/blue], ",")
  For i = 0 To UBound(varGroups)
    If UCase(varGroups(i)) = UCase(strGroup) Then
      InGroup = True
      Exit For
    End If
  Next i
End Function

VBSlammer
redinvader3walking.gif

"You just have to know which screws to turn." - Professor Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top