Form Password

P-C-Surgeon

Board Regular
Joined
Sep 24, 2004
Messages
115
Is there a way to create a link on a form which will open up another form but requres a password to open the 'password protected form'? Or should I just create my first form, which doesn't need a password, with a hidden link? I do have several forms which I don't want people to get into so I am trying to restrict access to these forms. Any ideas? Thanks for any suggestions.
 

Some videos you may like

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Andrew Fergus

MrExcel MVP
Joined
Sep 9, 2004
Messages
5,432
Hi

Insert the following code into the 'On Open' event of the form you want to protect :

Code:
Private Sub Form_Open(Cancel As Integer)

Dim PW As String

'Use either a DLookup to a table or hardcode the password in this code
'The line below is to extract the password from a table
PW = DLookup("[MyPasswordField]", "MyTable")

'Or the line below is to hard-code the password (delete one)
PW = "MyPassword"

If InputBox("Enter Administration Password ", "Password Required") <> PW Then
    MsgBox "Incorrect Password"
    DoCmd.Close acForm, "MyFormName", acSaveNo
    Exit Sub
End If

DoCmd.Restore

End Sub

Change any of the items prefixed with "My' to your actual field or table names. If the user tries to open the form, then the must enter the correct password to open the form.

HTH, Andrew :)
 

Watch MrExcel Video

Forum statistics

Threads
1,118,436
Messages
5,572,109
Members
412,441
Latest member
kelethymos
Top