Password protect a form

bellemmar

Registered User.
Local time
Today, 12:44
Joined
Mar 9, 2011
Messages
64
Hello,
How can I password protect access to a form? I have a public database that all employees use however I only want certain people to be able to view/edit one of the forms in it.
Is this possible?
Thanks!
 
So I've figured out how to do this with the following code:
Private Sub Form_Open(Cancel As Integer)
Dim pwd As String
pwd = InputBox("Authorized Users Only. Please enter password.")
If pwd = "Password" Then
MsgBox "Access granted."
Else
MsgBox "Incorrect password entered. Check that you are authorized to access this area."
DoCmd.Close
End If
End Sub

The trouble is, the code pops up as soon as the databse is opened, rather than only when someone tries to access the protected form. Any suggestions?
Thanks!
 
Take the code out of Form Open and put it into the On Click event of the command button which opens the form which you want to protect.

Then move the current "DoCmd.OpenForm" which the command button does to where the "MsgBox "Access granted."" is in the above code, that way the form will only open if the password is correct.
 
One more question...when the password is entered, it's visible. How can I make it show up as *******? Thanks!
 
An input box cannot mask the entry (a 3rd party add-on may alter this).

If I wanted input box functionality with an input mask I'd create a simple form with 1 textbox and 2 command prompts and make it look like a generic input box.

Instead of going from the main form to this restricted form and having the OnOpen event checking the password the main form would open the input box form and the ok command button on that form would check the password and open the restricted form if it matches.
 
Much appreciated; think I'll leave it visible. I don't think I'm savvy enough for that!!
 

Users who are viewing this thread

Back
Top Bottom