Thanks Brendan.
>'DAO method - requires DAO reference
>
>'ADOX method - requires ADOX reference
>? isuseringroupa(currentuser(),"Test")
>False
> Public Function IsUserInGroupD( _
> ByVal UserName As String, _
[quoted text clipped - 10 lines]
> Next grp
> End Function
Why iterate? You can test it directly, without having to loop. Also,
that code will fail with a runtime error if the specified user does not
exist.
This version returns True if the specified user exists AND the
specified group exists AND the specified user is a member of the
specified group - False otherwise:
Public Function IsUserInGroup( _
UserName As String, _
GroupName As String _
) As Boolean
dim s as string
on error resume next
s = dbengine(0)(0).users(UserName).groups(GroupName).name
isuseringroup = (err.number = 0)
End Function
Cheers,
TC
Brendan Reynolds - 27 Nov 2005 12:36 GMT
> Why iterate? You can test it directly, without having to loop.
Why not iterate? There would have to be tens of thousands of users and
groups before there would be any perceptible impact on performance.
> Also,
> that code will fail with a runtime error if the specified user does not
> exist.
Rightly so. Attempting to refer to a non-existant user is an error and
should be treated as such. Determining whether a user or a group exist is a
separate operation from determining whether a user is a member of a
specified group. They should be separate functions or, at the least, if they
are combined the function should return different results to distingusih
between the various possibilities - user and group exist, user is in group,
user and group exist, user is not in group, user exists, group doesn't, user
does not exist, group does.
IMHO of course! :-)

Signature
Brendan Reynolds