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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Authorizing Access to controls on a form 2

Status
Not open for further replies.

puforee

Technical User
Oct 6, 2006
741
US
I have a form that needs authorization for certain of its controls. When the form opens a text control contains the users ID of the person who opened the DB, (we will call it UserID). TekTips gave me this code-thanks. I use a simple VBA code to check for specific User ID's, if they match the restricted controls become active. This check code is stored on the On Current event of the Form. This is fine if I want to change the VBA code every time a user is added or removed.

So, I built a table to store the authorized userID's The table is called Access_control. The ID's are stored in a field called "User". This way the list of user's can be administered by one of the DB users. Changes to this table are password protected and only 1 or 2 people have the password.

So, I need VBA code that runs when the form is opened should compare the forms UsetID field to the Access_control table, User field to see it it matches one of the table entries. If it matches, the restricted controls are enabled.

I am using MS Office 2013 and this DB is to be used at work.

OR...is there a better way to control access to the restricted controls?

I anxiously look forward to your replies...please include sample code.
 
OK, I checked Tools - Options - Editor Tab and the Require Variable Declaration check box.

Again, please be patient, Where to I type Option Explicit? Duane said at the top of the page but the code page does not like it? Or did the check box do it? Also, in short, what does it do?

Thanks for all your help,

John
 
OptionExplicit_mp4p5u.jpg

Specifying Option Explicit checks the spelling of your memory variables when you compile (which you need to do regularly).


Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
the code page does not like it?" - what do you get when you have:

Code:
Option Compare Database[blue]
Option Explicit  [/blue]

Private Sub Form_Close()
    DoCmd.Restore
End Sub

...

Error messages?

"what does it do?" - requires you to declare all variables that you use in the code.
So you cannot use anything not declared, and also you cannot misspell the names of your variables.


---- Andy

There is a great need for a sarcasm font.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top