DAO Code to remove ALL the groups that a user belongs to

T

Tony_VBACoder

Using DAO with security applied to a Access2002 db, how
can I remove all the groups that a user is assigned to,
skipping the "Users" group, since all users need to be in
this group.

I am trying to write code that will first remove all the
groups and then re-add other groups.
 
A

Albert D. Kallal

To remove a user from a group, i use:

Public Sub RemoveFromSecGroup(strUserName As String, strGroupName As String)

' remove user from a group
Dim uUser As user
Dim gGroup As Group

Set uUser = DBEngine.Workspaces(0).Users(strUserName)

uUser.Groups.Delete strGroupName
uUser.Groups.Refresh


End Sub

And, to walk the susers groups..you can use:

Dim grp As Group
Dim usr As user

set user = DBEngine.Workspaces(0).Users("Albert")

For Each grp In usr.Groups
if grp.name <> "users" then
call RemoveFromSecGroup("Albert",grp.name)
end if
Next


And, here is a handy fcntion I use to test for in a group

Public Function IsInGroup(UsrName As String, GrpName As String) As Boolean
'Determines whether UsrName is a member of GrpName

Dim grp As Group
Dim IIG As Boolean
Dim usr As user

IIG = False
For Each usr In DBEngine.Workspaces(0).Users
For Each usr In DBEngine.Workspaces(0).Users
If usr.Name = UsrName Then GoTo FoundUser
Next

GoTo IIG_Exit

FoundUser:
For Each grp In usr.Groups
If grp.Name = GrpName Then IIG = True
Next

IIG_Exit:
IsInGroup = IIG


End Function
 
D

ddbhangale

Using DAO with security applied to a Access2002 db, how can I remove all the groups that a user is assigned to, skipping the "Users" group, since all users need to be in this group. I am trying to write code that will firstremove all the groups and then re-add other groups.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top