Check permissions for user in VBA?

geralf

Registered User.
Local time
Today, 05:48
Joined
Nov 15, 2002
Messages
212
Hi,
I want to check what permissions a user logged on my db has. I've checked out the AllPermissions and Permissions properties.

I would like to see if the user has permission to click a button or something else in a spesific form. Can this be done in VBA, and if so, how?

Thanks in advance for any help


Regards
Gerhard
 
One way (there are others) is to get the network UserName and use that as the basis for what buttons are enabled or disabled.

Col
 
Yes, thats what I use today. The downside to this is that any changes made to the workgroup file must also be done in my forms VBA code. I want to avoid this. What's the other way(s)?

Thanks for your reply ColinEssex
 
Last edited:
base the permissions upon the group rather than the individual users...

Regards
 
namliam
I only use thre 'users' instead of groups, because there are many people that use the same computer, and 'who does what' is not important. One 'user' has all rights as an admin, and all users who has admin rights log onto the db with the same username with the samw password. This works very fine. This is done to minimize the administration of the db as well.

If someone knows how to check the permissions a user has for a form, I'd be very happy to know how.

namliam, how would I do it if I used groups?

Thanks in advance
 
You can use

DBEngine.Workspaces(0).Username

To retrieve the currently loged on name.

Does that help?

Regards
 
Or try:

CurrentDb.Containers!Forms.Properties("Permissions")

Dont know the ins and outs of it... But its a starting point

Regards
 
namliam,
Thanks for your reply, but this isthe same I've tried out. My main goal here is to see what permission the current user has for a form using VBA.

I don't understand the container/document properly, because I'm interested in a spesific form in the container/document object.
 
The way I did it (as I'm not too good with workgroups so didn't bother with them) is to create a user's table consisting of UserName and Level. Add each userName to the table and give them a level (A,B,C or whatever)

Use the FosUerName() function to pick up their network name and then when the form is opened, check their name against your user table and get the level. Then if level = A that can mean use all buttons, level B can disable certain buttons and so on. I use it to allow inputters full access and managers limited access (cos they can screw things up!)

You can even have a LogIn table to post the UserName, Date and Login time to see who logs in and out and how long for.

Search these forums for FosUserName() and you'll find the code and how to do it. I seem to remember posting it a while back, I believe Mile-O also had some good suggestions too.

Hope this helps

Col
 
Thanks for your idea and reply Col.

I managed to make a function that I can use (I think). I haven't figured out all the return values yet. The function looks like this:

Function DocumentX(NameOfForm As String) As Long
Dim dbs As Database
Dim Doc As Document
Set dbs = CurrentDb
With dbs.Containers!Forms
With .Documents(NameOfForm)
DocumentX = .Permissions
End With
End With
dbs.Close
End Function

If I'm loggged on as an admin, it returns the vbSecFullAccess constant for the Permission property.

However, if I log on as a user with the following permissions:read,retrieve data,delete data,modify data, insert data, openDB, read Def, I get returned a value of 260. If I add together the constants, I get 250, so there's something I don't take into account here I think.

I also have a sample db posted at UtterAccess which creates tables with all the permissions for the workgroup file. I'll check it out today if I get the time.


Thanks again and have a nice day!
 

Users who are viewing this thread

Back
Top Bottom