Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

10 views
Skip to first unread message

Tony_VBACoder

unread,
Jul 1, 2004, 3:59:18 PM7/1/04
to
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.

Albert D. Kallal

unread,
Jul 1, 2004, 5:02:35 PM7/1/04
to
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


--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pleaseNOO...@msn.com
http://www.attcanada.net/~kallal.msn


ddbha...@gmail.com

unread,
Dec 5, 2012, 8:11:51 AM12/5/12
to
0 new messages