Hi Jim,
I'll give you a couple of methods, the first involves 2 functions - one to
ensure that the group exists, then if it does exist, the second to determine
whether the user is in the group. This method is a bit more reliable than
the second I'll show later:
Public Function IsUserInGroup(strUser As String, _
strGroup As String) As Boolean
Dim ws As dao.Workspace
Dim strUserName As String
Dim usr As dao.User
Dim inti As Integer
Dim fIsUserInGroup As Boolean
Set ws = DBEngine.Workspaces(0)
If GroupExists(strGroup) Then
For inti = 0 To ws.Groups(strGroup).Users.count - 1
If ws.Groups(strGroup).Users(inti).Name = strUser Then
fIsUserInGroup = True
End If
Next inti
End If
IsUserInGroup = fIsUserInGroup
set ws=nothing
End Function
Public Function GroupExists(strGroup) As Boolean
Dim ws As dao.Workspace
Dim strUserName As String
Dim usr As dao.User
Dim inti As Integer
Dim fGroupExists As Boolean
Set ws = DBEngine.Workspaces(0)
For inti = 0 To ws.Groups.count - 1
If ws.Groups(inti).Name = strGroup Then
fGroupExists = True
End If
Next inti
GroupExists = fGroupExists
set ws=nothing
End Function
Here's the one function method - note that it does not differentiate the
error that occurs if marked line fails.
Function IsUserInGroup(strUser As String, _
strGroup As String) As Boolean
Dim ws As Workspace
Dim strUserName As String
Set ws = DBEngine.Workspaces(0)
On Error Resume Next
' if this line fails then the user is not in the group
strUserName = ws.Groups(strGroup).Users(strUser).Name
IsUserInGroup = (Err = 0)
End Function