Problems in adding Users to a Group

L

Leif

I'm able to add users to a group using VBA. The code
follows:

Sub AddUserToGroup(addGrp As String)

Dim ws As DAO.Workspace
Dim usr As DAO.User
Dim grp As DAO.Group

If Not IsUserMember(addGrp) Then
Set ws = DBEngine.CreateWorkspace("Temp", "System
User", "System Password")
Set usr = ws.Users(CurrentUser())
Set grp = usr.CreateGroup(addGrp)
usr.Groups.Append grp

Set usr = Nothing
Set grp = Nothing
ws.Close
Set ws = Nothing

DBEngine.Idle
End If
End Sub

addGrp is a string with the group name to be added.
System User belongs to Admins.

It works fine, the problem is the changes don't take
effect until the user logs out/in again. Since I'm using
this in an Autoexec routine I would like the changes to
take effect immediately.

I know I can get it to work using individual tables, as
demonstrated in SECFAQ.DOC. But it would be much cleaner
if I can just Add/Remove users from a group.

Thanks,
Leif
 
L

Leif

Still no joy. I've changed my code as follows:

Sub AddUserToGroup(addGrp As String)

Dim db As DAO.Database
Dim ws As DAO.Workspace
Dim usr As DAO.User
Dim grp As DAO.Group

If Not IsUserMember(addGrp) Then
Set ws = DBEngine.CreateWorkspace("Temp", "System
User", "System Password")

Set usr = ws.Users(CurrentUser())
Set grp = usr.CreateGroup(addGrp)
usr.Groups.Append grp
ws.Users.Refresh
ws.Groups.Refresh

Set usr = Nothing
Set grp = Nothing

ws.Close
Set ws = Nothing

Set ws = DBEngine.Workspaces(0)
ws.Users.Refresh
ws.Groups.Refresh

ws.Close
Set ws = Nothing

End If
End Sub

Notice in desperation I even try a refresh in the default
workspace.

Leif
-----Original Message-----
Use Refresh method. For instance:

ws.Users.Refresh
ws.Groups.Refresh

HTH
--
[]'s JR
http://www.accessjr.cjb.net/ (pt-br version)
Leif said:
I'm able to add users to a group using VBA. The code
follows:

Sub AddUserToGroup(addGrp As String)

Dim ws As DAO.Workspace
Dim usr As DAO.User
Dim grp As DAO.Group

If Not IsUserMember(addGrp) Then
Set ws = DBEngine.CreateWorkspace ("Temp", "System
User", "System Password")
Set usr = ws.Users(CurrentUser())
Set grp = usr.CreateGroup(addGrp)
usr.Groups.Append grp

Set usr = Nothing
Set grp = Nothing
ws.Close
Set ws = Nothing

DBEngine.Idle
End If
End Sub

addGrp is a string with the group name to be added.
System User belongs to Admins.

It works fine, the problem is the changes don't take
effect until the user logs out/in again. Since I'm using
this in an Autoexec routine I would like the changes to
take effect immediately.

I know I can get it to work using individual tables, as
demonstrated in SECFAQ.DOC. But it would be much cleaner
if I can just Add/Remove users from a group.

Thanks,
Leif


.
 
L

Leif

Hi JR,

Yes, that will add a user to a group. In fact you can
bring up the User and Group Accounts... dialog and see the
user is added. *However*, in my experience if you do this
while the user is logged in, even tho' you see he is in
the group, that user *does not* have the permissions of
the group. It appears to only be assigned on login. If
the user logs out and back in again, then the user gets
the permissions of the group.

Regards,
Leif
 

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