Has somebody code for a function, which receives a username and a user group name as input, and returns True if the user belongs to the specified group ?
If you have a table in your db called tblGroupList that is set up with 2 fields, username & groupname then you could use the dlookup function:
Function InGroup(sUserName as string, sGroupName as String) as Boolean
if Dlookup("GroupName","tblGroupList","UserName='" & sUserName & "'"=sGroupName then
Ingroup=true
else
ingroup=false
end if
end function
HTH
Ben ----------------------------------
Ben O'Hara
Home: bpo@RobotParade.co.uk
Work: bo104@westyorkshire.pnn.police.uk
Web:
But what I am interested in is the check of the MS Access catalog. Currently, I use the access protection, so each user belongs to one or more user groups. So I need code to analyze the user and group definitions within access.
If you are using Access 2000 or above here are a couple of functions you can check out and modify as needed.
Function JetSecurity2()
'-- 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
Function InGroup(Iuser As String, Igrp As String) As String
'-- 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
InGroup = "No"
Dim ur As User, gp As Group
For Each ur In cg.Users
Debug.Print "Users = "; ur.Name
If ur.Name = Iuser Then
For Each gp In ur.Groups
Debug.Print " Group = "; gp.Name
If gp.Name = Igrp Then
InGroup = "Yes"
End If
Next
End If
Next
Debug.Print "In Group = "; InGroup
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.