Programmatically add User to Group?

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.
 
J

Joan Wild

It's in the security FAQ:

Set ws= DBEngine.Workspaces(0)
With ws
.Groups("SomeGroup").Users.Append "UserName"
.Groups.Users.Refresh
End With
 
G

Guest

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
 
G

Guest

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.
 
J

Joan Wild

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
 
G

Guest

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"
 

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