Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preventing code from running if user is read-only

Status
Not open for further replies.

MarkWaddington

Programmer
Aug 19, 2002
64
GB
Hi, is there any code I can use that will prevent code from being executed if the particular database user is read-only.

Basically, I have a user-update section on my main form which updates itself with the username of who edited the record last. This causes errors when somebody logs in who is only read-only.

Thanks in advance.

Mark Waddington.
 
Hi!

If you put the code to change the last updated field in the BeforeUpdate event procedure then the code will never run if the user has read-only priviledges because they would have to change something to make the procedure run and they can't. But, for a general answer to your question, put the code in an if statement that checks the user group or security level(however you set up the read only) for the current user and run the code only if the user is in a group with update access.

hth
Jeff Bridgham
bridgham@purdue.edu
 
Thanks for the reply. If a read-only user just views the form it still comes up with errors even though nothing on the form has changed. I don't really understand this, but what I wanted to know, is how do i REFER in the code as to whether or not a user is read-only.

I'm sure it will be something like:

If (CurrentUser() = Readonly)

Then... etc


I'm not very good at code and I just can't work it out!

Thanks,

Mark.
 
Try this:

Code:
    Dim cat As New ADOX.Catalog
    Dim cnn As ADODB.Connection
    Dim szUser As String
    Dim szPermission As String
    
    Set cnn = CurrentProject.Connection
    Set cat.ActiveConnection = cnn
    szUser = cat.Users.Item(1).Name
    szPermission = cat.Users.Item(1).GetPermissions("nNote ID", adPermObjTable)
    MsgBox szUser & "  " & szPermission
You could use a loop to search through all of the users and check permission when the usernames match.
getpermissions returns a long.

In MS help, search for "rights enum" and select "rightsenum"
for a list of what the number means.

Hope this is helpful.
ADOX requires the "Microsoft ADO Ext. 2.X for DLL and Security" reference.
 
here is a simpler to my opinion solution:

for each control that you want readonly write for ONCURRENT, OR ONOPEN
if currentuser<>&quot;admin&quot; then
controlX.locked=true

or controlx.enabled=false

or try
IF currentuser<>&quot;ADMIN&quot; then
AllowEdits = False
AllowDeletions = False
AllowAdditions = False
end if
REGARDS, KUZZ

LIFE IS GREAT WHEN THERE IS SOMEONE TO HELP YOU.
DESIGNING DATABASES SINCE 2002
 
Mark,

Are you trying to find out the permissions of the user and then running appropriate code or do you have code to handle checking permissions and want to know how to lock stuff?

Dalton
 
Good question Dalton REGARDS, KUZZ

LIFE IS GREAT WHEN THERE IS SOMEONE TO HELP YOU.
DESIGNING DATABASES SINCE 2002
 
Thanks for the replies guys, I don't understand what you said in your first post Dalton, it took me all my time figuring out relationships are..! Never mind trying to decipher that code, but thanks anyway :)

I'm trying to test for the permissions of the current user and then code for that. The current user may be an &quot;admin&quot; but their username may not necessarily be &quot;admin&quot; (if you understand!) I just want an if..else.. statement which would prevent READ-ONLY users from running a piece of code.. no other users.

Thanks.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top