VBA User Permissions

jennilewis

Registered User.
Local time
Today, 23:31
Joined
Aug 11, 2005
Messages
16
Is there a way in which to assign user permissions to vba code?
I have some command buttons which run vba code but i only want to allow certain users to use these.
 
I have done this before:

On a form I have a textbox that gets the users logon name. Set the visible property of the command button to no. In the onload event of the form is this:

If Me.textbox = "whateveruseryouchoose" Then
YourButton.Visible = True
End If
 
jrjr has given you good advice. If you look at the Tools >> Security >> Permissions dialog box, permissions do not apply to any object smaller than a whole form. Controls, being smaller (lower level) objects than a form, are left out. So you have to "roll your own" security for this situation.

Since you HAVE some VBA code already, add a bit more code under the button to identify & qualify the user (and ignore the operation for unauthorized users). OR, in the Form_OnLoad event, pre-qualify the user and disable or hide the controls they aren't supposed to see.
 
will i need to repeat the two lines of if statement for each user i want to be able to use the button?
 
also if this hides the button where do i need to put the code in order for it to work? the form it is on is always open.
thanks!
 
also if this hides the button where do i need to put the code in order for it to work? the form it is on is always open.

If the form is always open on each user's workstation, and you have more than a couple of users, if the form is bound to a record, you are risking record lock issues.

Be that as it may, you probably need to do this in the Form_OnLoad event which gets run when the form opens on the workstation.

In the form's class module, OnLoad event, create a couple of variables. Store the name of the user as obtained from CurUser function (look this one up in the Help files). Determine whether the user does - or doesn't - have the right. Store a TRUE/FALSE value in a Boolean variable.

Now, still in the OnLoad routine, you will have a list of things that look like this:

Button1.Enabled = Boolean variable
Button2.Enabled = Boolean variable
Button3.Enabled = Boolean variable
etc.

After that, you can end the event routine.

If you have implemented workgroup security properly, your users get their permissions from a group (of which they are a member). So one thing you could do is realize that each form is connected to a collection of Users and each user includes a collection of associated Groups. You could write a separate function to find the user's group and decide Yes or No based on group membership inside the function. Just a thought, there are other ways to do this. I would do it this way because it is technically correct and less likely to be discombobulated by future upgrades to Access itself. But that's just me.
 
the form is literally just a switchboard with buttons to navigate around the database. This shouldn't be too much of a problem should it?
 
jennilewis said:
the form is literally just a switchboard with buttons to navigate around the database. This shouldn't be too much of a problem should it?


If you have multiple levels of users and have a tough time getting the switchboard to look correct when you are turning buttons on and off, here is a thought.

Create a hidden form that opens when the DB opens. Use whatever suggestions you prefer above to determine the user's level. Have multiple switchboards (custom forms) and depending on the user, open that switchboard for them to use from the hidden form.

Edit:

jennilewis said:
will i need to repeat the two lines of if statement for each user i want to be able to use the button?


If Me.textbox = "userone" or Me.textbox = "usertwo" or Me.textbox = "usethree" Then

YourButton1.Visible = True
YourButton2.Visible = True
YourButton3.Visible = True
YourButton4.Visible = True

End If


Etc....
 
Last edited:

Users who are viewing this thread

Back
Top Bottom