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] |