Append New user to A Group

J

Jim Bunton

* I cannot append a new user to a group!
* Windows 2000 [Ia m Administrator]
* Access 97 I am logged in as a member of Admins
I own every object
I have full permission on every object
--------------------------------------------
I have now resorted to almost the identical code in the Access 97 help files
Users Object (DAO)
- code example 1 [with additions]
'CreateUser Method and Password and PID Properties Example'
[began without the additions]
-------------------------------------------


=== Code start =====
Private Sub Command2_Click()
On Error GoTo Err_Command2_Click
Dim WkSpace As Workspace, grpNew As Group, usrTemp As User
Dim usrMine As User

Set WkSpace = DBEngine.Workspaces(0)

With WkSpace
' Create and append new Group.
Set grpNew = .CreateGroup("NewGroup", "AAA123456789")
'THE NEXT succeeds
.Groups.Append grpNew

' Make the user "NewUser" a member of the
'group "NewGroup" by creating and adding the
'appropriate User object to the group's Users
'collection.
Set usrTemp = .Groups("NewGroup").CreateUser("NewUser")
Set usrMine = .CreateUser("MyNewUser", "123456", "Pwd")
'usrTemp.PID = "AAA123456789"
'usrTemp.Password = "NewPassword"
'THE NEXT fails
' 3030 'NewUser' Isn't valid account
.Groups("NewGroup").Users.Append usrTemp
'THE NEXT succeeds
.Users.Append usrMine
'THE NEXT Fails
'3219 - Invalid Operation
.Groups("NewGroup").Users.Append usrMine

End With


Exit_Command2_Click:
Exit Sub

Err_Command2_Click:
MsgBox Err & " - " & Err.Description
Resume Next

End Sub
==== Code End ====


--
Jim Bunton
(e-mail address removed)
13 Westbourne Road
Trowbridge
Wilts. BA14 0AJ
Tel: 01225 765 541
Mobile: 07919 283 968
 
J

Jim Bunton

BUT Note also that though
'THE NEXT succeeds
.Users.Append usrMine
usrMine, i.e."MyNewUser" does not belong to the 'Users' Group when inspected
with Tools>Security>acounts!


Jim Bunton said:
* I cannot append a new user to a group!
* Windows 2000 [Ia m Administrator]
* Access 97 I am logged in as a member of Admins
I own every object
I have full permission on every object
--------------------------------------------
I have now resorted to almost the identical code in the Access 97 help files
Users Object (DAO)
- code example 1 [with additions]
'CreateUser Method and Password and PID Properties Example'
[began without the additions]
-------------------------------------------


=== Code start =====
Private Sub Command2_Click()
On Error GoTo Err_Command2_Click
Dim WkSpace As Workspace, grpNew As Group, usrTemp As User
Dim usrMine As User

Set WkSpace = DBEngine.Workspaces(0)

With WkSpace
' Create and append new Group.
Set grpNew = .CreateGroup("NewGroup", "AAA123456789")
'THE NEXT succeeds
.Groups.Append grpNew

' Make the user "NewUser" a member of the
'group "NewGroup" by creating and adding the
'appropriate User object to the group's Users
'collection.
Set usrTemp = .Groups("NewGroup").CreateUser("NewUser")
Set usrMine = .CreateUser("MyNewUser", "123456", "Pwd")
'usrTemp.PID = "AAA123456789"
'usrTemp.Password = "NewPassword"
'THE NEXT fails
' 3030 'NewUser' Isn't valid account
.Groups("NewGroup").Users.Append usrTemp
'THE NEXT succeeds
.Users.Append usrMine
'THE NEXT Fails
'3219 - Invalid Operation
.Groups("NewGroup").Users.Append usrMine

End With


Exit_Command2_Click:
Exit Sub

Err_Command2_Click:
MsgBox Err & " - " & Err.Description
Resume Next

End Sub
==== Code End ====


--
Jim Bunton
(e-mail address removed)
13 Westbourne Road
Trowbridge
Wilts. BA14 0AJ
Tel: 01225 765 541
Mobile: 07919 283 968
 
J

Joan Wild

You need to refresh the Users collection after appending the user (and also
the groups after creating the group)
.Groups.Append grpNew
.Groups.Refresh
and
.Users.Append usrMine
.Users.Refresh

And you need to add the user to the Users group, and then add them to your
Group.

--
Joan Wild
Microsoft Access MVP



Jim said:
BUT Note also that though
'THE NEXT succeeds
.Users.Append usrMine
usrMine, i.e."MyNewUser" does not belong to the 'Users' Group when
inspected with Tools>Security>acounts!


Jim Bunton said:
* I cannot append a new user to a group!
* Windows 2000 [Ia m Administrator]
* Access 97 I am logged in as a member of Admins
I own every object
I have full permission on every object
--------------------------------------------
I have now resorted to almost the identical code in the Access 97
help files Users Object (DAO)
- code example 1 [with additions]
'CreateUser Method and Password and PID Properties Example'
[began without the additions]
-------------------------------------------


=== Code start =====
Private Sub Command2_Click()
On Error GoTo Err_Command2_Click
Dim WkSpace As Workspace, grpNew As Group, usrTemp As User
Dim usrMine As User

Set WkSpace = DBEngine.Workspaces(0)

With WkSpace
' Create and append new Group.
Set grpNew = .CreateGroup("NewGroup", "AAA123456789")
'THE NEXT succeeds
.Groups.Append grpNew

' Make the user "NewUser" a member of the
'group "NewGroup" by creating and adding the
'appropriate User object to the group's Users
'collection.
Set usrTemp = .Groups("NewGroup").CreateUser("NewUser")
Set usrMine = .CreateUser("MyNewUser", "123456", "Pwd")
'usrTemp.PID = "AAA123456789"
'usrTemp.Password = "NewPassword"
'THE NEXT fails
' 3030 'NewUser' Isn't valid account
.Groups("NewGroup").Users.Append usrTemp
'THE NEXT succeeds
.Users.Append usrMine
'THE NEXT Fails
'3219 - Invalid Operation
.Groups("NewGroup").Users.Append usrMine

End With


Exit_Command2_Click:
Exit Sub

Err_Command2_Click:
MsgBox Err & " - " & Err.Description
Resume Next

End Sub
==== Code End ====


--
Jim Bunton
(e-mail address removed)
13 Westbourne Road
Trowbridge
Wilts. BA14 0AJ
Tel: 01225 765 541
Mobile: 07919 283 968
 
J

Jim Bunton

Hm! - am I doing something obsurdly stupid?
This all works until
.Groups("Users").Users.Append UsrNew
=======================
With WkSpace
Set UsrNew = .CreateUser("aNewUser", "123456", "Pwd")
.Users.Append UsrNew
.Users.Refresh
.Groups.Refresh
.Groups("Users").Users.Refresh
Set UsrNew = .Users("aNewUser")
MsgBox UsrNew.Name & " - " & .Groups("Users").Name
.Groups("Users").Users.Append UsrNew
'AHHHH - Error
'Err 3219 - Invalid operation
'Mystified
End with
========================
Joan Wild said:
You need to refresh the Users collection after appending the user (and also
the groups after creating the group)
.Groups.Append grpNew
.Groups.Refresh
and
.Users.Append usrMine
.Users.Refresh

And you need to add the user to the Users group, and then add them to your
Group.

--
Joan Wild
Microsoft Access MVP



Jim said:
BUT Note also that though
'THE NEXT succeeds
.Users.Append usrMine
usrMine, i.e."MyNewUser" does not belong to the 'Users' Group when
inspected with Tools>Security>acounts!


Jim Bunton said:
* I cannot append a new user to a group!
* Windows 2000 [Ia m Administrator]
* Access 97 I am logged in as a member of Admins
I own every object
I have full permission on every object
--------------------------------------------
I have now resorted to almost the identical code in the Access 97
help files Users Object (DAO)
- code example 1 [with additions]
'CreateUser Method and Password and PID Properties Example'
[began without the additions]
-------------------------------------------


=== Code start =====
Private Sub Command2_Click()
On Error GoTo Err_Command2_Click
Dim WkSpace As Workspace, grpNew As Group, usrTemp As User
Dim usrMine As User

Set WkSpace = DBEngine.Workspaces(0)

With WkSpace
' Create and append new Group.
Set grpNew = .CreateGroup("NewGroup", "AAA123456789")
'THE NEXT succeeds
.Groups.Append grpNew

' Make the user "NewUser" a member of the
'group "NewGroup" by creating and adding the
'appropriate User object to the group's Users
'collection.
Set usrTemp = .Groups("NewGroup").CreateUser("NewUser")
Set usrMine = .CreateUser("MyNewUser", "123456", "Pwd")
'usrTemp.PID = "AAA123456789"
'usrTemp.Password = "NewPassword"
'THE NEXT fails
' 3030 'NewUser' Isn't valid account
.Groups("NewGroup").Users.Append usrTemp
'THE NEXT succeeds
.Users.Append usrMine
'THE NEXT Fails
'3219 - Invalid Operation
.Groups("NewGroup").Users.Append usrMine

End With


Exit_Command2_Click:
Exit Sub

Err_Command2_Click:
MsgBox Err & " - " & Err.Description
Resume Next

End Sub
==== Code End ====


--
Jim Bunton
(e-mail address removed)
13 Westbourne Road
Trowbridge
Wilts. BA14 0AJ
Tel: 01225 765 541
Mobile: 07919 283 968
 
J

Joan Wild

Dim wrk As Workspace
Dim usrNew As User
Dim grp As Group

Set wrk = DBEngine.Workspaces(0)

'Create new group
Set grp = wrk.CreateGroup("MyGroup", "12345")
wrk.Groups.Append grp

'Create new user
Set usrNew = wrk.CreateUser("SomeUser", "98766", "SomePassword")
wrk.Users.Append usrNew

'Add user to Users and MyGroup groups
wrk.Groups.Refresh
wrk.Users.Refresh

usrNew.Groups.Append wrk.CreateGroup("Users")
usrNew.Groups.Append wrk.CreateGroup("MyGroup")
 
J

Jim Bunton

Thanks for persisting Joan.

I now see the error of my ways -
confused by having to use syntax that inferred the creation of a Group that
already existed.
All now working fine - thanks again
 

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