Programmatically add User to Group?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I programmatically add an existing User to another existing Group? I
found code using the CreateUser Method (Help Menu) to create a new User and
assign to a new Group. What about existing Users? I'm working with Access
2003. Thanks in advance.
 
It's in the security FAQ:

Set ws= DBEngine.Workspaces(0)
With ws
.Groups("SomeGroup").Users.Append "UserName"
.Groups.Users.Refresh
End With
 
Thanks for the reply, Joan.

I had to modify the code due to compile error. However, I am getting a 3219
Invalid Operation error. Any ideas? Here is the code:

Dim ws As Workspace
Set ws = DBEngine.Workspaces(0)
With ws
.Groups("Read-Only Users").Users.Append .Users("test")
.Users.Refresh
End With
 
Yes, I have reviewed this FAQ. The example shows the code when creating new
users. My dilemma is that I have 100+ existing user IDs that I want assigned
to a particular group. Is there a way to assign existing users to groups?
Thanks.
 
Yes there is. My earlier code was incorrect, sorry. The CreateUser method
must be in there (even though you aren't creating a user).

Dim ws As Workspace
Dim grpUsers as Group
Dim usr as User

Set ws = DBEngine.Workspaces(0)
Set grpUsers = ws.Groups("Read-Only Users")
Set usr = grpUsers.CreateUser("test")

grpUsers.Users.Append usr
grpUsers.Users.Refresh
 
Cool! Thanks for your help.
The user gets added to the group. However, existing group memberships
remain intact, but I can get around that by deleting the groups altogether
with: .Groups.Delete "MyGroup"
 
Back
Top