473,395 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

Nov 13 '05 #1
1 2208
-----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:
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

Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: ColdCanuck | last post by:
Greetings! I am VERY new to DB2 but not Orable, Sybase and SQL Server. I am trying to call a stored procedure via VB 6 and ADO/OLEDB. But when I try to execute
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
16
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
6
by: quilkin | last post by:
I am getting a System.Data.SqlClient.SqlException with a message string of 'Unknown Error'. Happens occasionally when creating a "new SqlCommand(...)" while the same command works perfectly happily...
3
by: Tim::.. | last post by:
Can someone please tell me why I'm getting the following error! I have absolutely no idea why this error keeps appearing! Thanks for any help! Compiler Error Message: BC30390:...
6
by: Jack | last post by:
I have the following asp script which I am trying to run against sql server. <HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> <TITLE>Chapter 12 - Command...
3
by: alnug | last post by:
Hello, I'm trying to use the following code to read data from Excel files and put the data into an MS Access Table. Some of the Excel files have the tabs in the sequence Chart1, Sheet1, Sheet2 etc...
25
by: premprakashbhati | last post by:
i want to have checkboxes in my gridview ...by checking it ,i can delete the row/rows.... so i have written code and got 2 Errors ...can anyone solve it... Error:1...'gridview.RetrieveItems()': not...
3
by: Vee007 | last post by:
Following is my code: Dim objCatalog As ADOX.Catalog Dim objTableLink As ADOX.Table Dim objADOConnection As ADODB.Connection Try objADOConnection = New...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.