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

  • Thread starter Thread starter Tony_VBACoder
  • Start date Start date
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.
 
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
 
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.
 
Back
Top