title: How to iterate active directory groups (roles) in MS Access VBA
body: <p>I have some code which will return true if a user is in a specific group that I pass in, however if the user is in another group that is part of the goroup I'm passing in, the function will return false. I need to be able to iterate through the groups to see if the user may be a member of a group that is in the group I'm interested in. </p>
  
  <p>So as an example, if a user is in GroupA and all members of Group_A are in Group_B and I need to know if the user is in Group_B, which they are by being in Group_A.
  Here is what I have now:
  ****EDIT added function GetCurrentUser used in IsUserInRole() </p>
  
  <pre><code>Public Function GetCurrentUser() As String
      GetCurrentUser = Environ("USERNAME")
  End Function
  
  Public Function IsUserInRole(role) As Boolean
  Dim UserObj As Object
  Dim GroupObj As Object
  
  Dim strObjectString As String
  strObjectString = "WinNT://my domain/" &amp; GetCurrentUser() &amp; ""
  Set UserObj = GetObject(strObjectString)
  
  For Each GroupObj In UserObj.Groups
  
  Debug.Print GroupObj.Name
  
     If GroupObj.Name = role Then
          IsUserInRole = True
          Exit Function
     End If
  Next
  </code></pre>
  
  <p>End Function</p>