Connecting Tech Pros Worldwide Help | Site Map

Error trying to append user to groups user collection

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 13th, 2005, 08:28 AM
Access
Guest
 
Posts: n/a
Default Error trying to append user to groups user collection

Here is my function to change a users permission level in the database.
This relates to an Access database secured using Access security.
This function is called if the end user changes a staff members access.
The two options are 1 = Normal User and 2 = Super User.

It gets down to the line
..Users.Append usr

and generates an error 3129 Invalid Operation.


Public Function changePermissionLevel(strUsername As String,
bytOldPermissionLevel As Byte, bytNewPermissionLevel As Byte) As
Boolean
On Error GoTo err_changePermissionLevel
Dim ws As Workspace
Dim usr As User
Dim grp As Group

'if there is something to do
If bytOldPermissionLevel <> bytNewPermissionLevel Then
Set ws = DBEngine.Workspaces(0)
'remove existing group access
For Each grp In ws.Groups
'if it's one of my groups
If grp.Name = "Update Data Users" Or grp.Name = "Admins"
Then
'remove the user from the group
For Each usr In grp.Users
If usr.Name = strUsername Then
grp.Users.Delete strUsername
End If
Next usr
End If
Next grp

'reset permission access
If bytNewPermissionLevel = 1 Then
With ws.Groups("Update Data Users")
Set usr = ws.Users(strUsername)
.Users.Append usr
End With
Else
With ws.Groups("Admins")
Set usr = ws.Users(strUsername)
.Users.Append usr
End With
End If
End If

err_changePermissionLevel:
If Err = 0 Then
changePermissionLevel = True
Else
changePermissionLevel = False
End If
End Function


  #2  
Old November 13th, 2005, 08:29 AM
MGFoster
Guest
 
Posts: n/a
Default Re: Error trying to append user to groups user collection

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You have to create a new User in the group before appending to the
group's Users collection.

Replace this:

Set usr = ws.Users(strUsername)
.Users.Append usr

with this:

.Users.Append .CreateUser(strUserName)

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQkdRTYechKqOuFEgEQL/4gCfZeqmYEFLGsKsqYGqtnajXR2SOnoAoNxZ
FtGvYFF+FIvXA27HJXmDttix
=KSnQ
-----END PGP SIGNATURE-----


Access wrote:[color=blue]
> Here is my function to change a users permission level in the database.
> This relates to an Access database secured using Access security.
> This function is called if the end user changes a staff members access.
> The two options are 1 = Normal User and 2 = Super User.
>
> It gets down to the line
> .Users.Append usr
>
> and generates an error 3129 Invalid Operation.
>
>
> Public Function changePermissionLevel(strUsername As String,
> bytOldPermissionLevel As Byte, bytNewPermissionLevel As Byte) As
> Boolean
> On Error GoTo err_changePermissionLevel
> Dim ws As Workspace
> Dim usr As User
> Dim grp As Group
>
> 'if there is something to do
> If bytOldPermissionLevel <> bytNewPermissionLevel Then
> Set ws = DBEngine.Workspaces(0)
> 'remove existing group access
> For Each grp In ws.Groups
> 'if it's one of my groups
> If grp.Name = "Update Data Users" Or grp.Name = "Admins"
> Then
> 'remove the user from the group
> For Each usr In grp.Users
> If usr.Name = strUsername Then
> grp.Users.Delete strUsername
> End If
> Next usr
> End If
> Next grp
>
> 'reset permission access
> If bytNewPermissionLevel = 1 Then
> With ws.Groups("Update Data Users")
> Set usr = ws.Users(strUsername)
> .Users.Append usr
> End With
> Else
> With ws.Groups("Admins")
> Set usr = ws.Users(strUsername)
> .Users.Append usr
> End With
> End If
> End If
>
> err_changePermissionLevel:
> If Err = 0 Then
> changePermissionLevel = True
> Else
> changePermissionLevel = False
> End If
> End Function
>[/color]
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.