Passwords on Forms (1 Viewer)

davey3389

Registered User.
Local time
Today, 22:47
Joined
Jul 16, 2012
Messages
30
Can some tell me how I would go about putting a password on a form when someone tries to open it

The form name is "Employee Details"

and also where would I set/change the password

Many Thanks

Ben
 

Trevor G

Registered User.
Local time
Today, 22:47
Joined
Oct 1, 2009
Messages
2,341
You can do this by adding a command button and then using some code like this:

Private Sub Command31_Click()
Dim strPassword As String
strPassword = "Test"
If InputBox("Please enter the password") = strPassword Then
DoCmd.OpenForm "frmClient"
Else
MsgBox "Incorrect Password used"
End If
End Sub
 

davey3389

Registered User.
Local time
Today, 22:47
Joined
Jul 16, 2012
Messages
30
Where do I type this code into
 

Trevor G

Registered User.
Local time
Today, 22:47
Joined
Oct 1, 2009
Messages
2,341
If you have a start form add a command button (in design view) and then open the properties for the command button, look at the Event Tab and then click the On Click Event and use the 3 dots to the right and select Code Builder copy and paste the code I added make sure you change the password to the one you want in the code and also don't copy the first line or last line as this is the command button name.
 

davey3389

Registered User.
Local time
Today, 22:47
Joined
Jul 16, 2012
Messages
30
I did the code, click the button it asked for the password and then when I typed it in i got the error message: Compile error: Expected End Sub

Any suggestions?

Thanks
 

Trevor G

Registered User.
Local time
Today, 22:47
Joined
Oct 1, 2009
Messages
2,341
At the end of the code does it show you

End Sub
 

davey3389

Registered User.
Local time
Today, 22:47
Joined
Jul 16, 2012
Messages
30
Here is a copy of the code:

*Note the top line is highlighted yellow


Private Sub Form_Open(Cancel As Integer)
Private Sub Command31_Click()
Dim strPassword As String
strPassword = "Test"
If InputBox("Please enter the password") = strPassword Then
DoCmd.OpenForm "frmClient"
Else
MsgBox "Incorrect Password used"
End If
End Sub
 

davey3389

Registered User.
Local time
Today, 22:47
Joined
Jul 16, 2012
Messages
30
Sorry I just worked out why, thanks for all the help
 

davey3389

Registered User.
Local time
Today, 22:47
Joined
Jul 16, 2012
Messages
30
On this subject is there away to make the password come up as **** rather than a visible password
 

Users who are viewing this thread

Top Bottom