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

find out which group a user belongs to.

Status
Not open for further replies.

tomlander

Programmer
Jul 10, 2002
15
0
0
CA
In VBA, can I find out what group/groups a user belongs to?

Thanks.
 
If you are using Access 2000 and ADO then paste this function into the standard module and run it.


Function JetSecurity()
'-- set reference to ADOX library
'- Microsoft ADO Ext. 2.6 for DDL and Security
'-- Microsoft ActiveX data objects 2.6 library also needed for ADO

Dim cg As New ADOX.Catalog
Set cg.ActiveConnection = CurrentProject.Connection

Dim ur As User, gp As Group
For Each ur In cg.Users
Debug.Print "Users = "; ur.Name

For Each gp In ur.Groups
Debug.Print " Group = "; gp.Name

Next
Next

End Function
 
And just another way. Give it a username and a groupname and you will get a boolean response. This doesn't user ADOX but relies solely on Access.

Public Function UserIsMemberOfGroup(strUsr As String, strGrp As String) As Boolean


' This function determines the groups the current user is assigned
' and returns true if the user is a member of the group being
' tested by the parameter strGrp
' Parameters:
' strUsr is a string value for the user to test
' strGrp is a string value for a valid group

Dim wsp As DAO.Workspace
Dim DBS As DAO.Database
Dim usr As User
Dim grp As Group
Dim strGrps As String

On Error GoTo HandleErr

' Return reference to default workspace.
Set wsp = DBEngine.Workspaces(0)
' Return reference to current database.
Set DBS = CurrentDb
' Set User object to the CurrentUser
Set usr = wsp.Users(strUsr)

For Each grp In usr.Groups
If grp.Name = strGrp Then
UserIsMemberOfGroup = True
GoTo Proc_Exit
End If
DocSkip:
Next grp

Proc_Exit:
Set wsp = Nothing
Set DBS = Nothing
Set usr = Nothing
Set grp = Nothing
Exit Function

HandleErr:
Select Case Err.Number
Case Else
Call HandleTheError("basPermissions", "UserIsMemberOfGroup", Err, ShowMsg)
End Select
Resume Proc_Exit
Resume

End Function
----------------------
scking@arinc.com
Life is filled with lessons.
We are responsible for the
results of the quizzes.
-----------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top