You really should google in the first instance, as many of the answers you want are avaliable.
None the less:
Open the switchboard form in design view and select the command button.
Select the On Click event and choose Event Procedure from the drop down list. Click on the ellipses (...) to enter the code window.
-
Private Sub cmdOpenEmpForm_Click()
-
-
'Attached to On Click event of cmdOpenEmpForm
-
-
Dim strPasswd
-
-
strPasswd = InputBox("Enter Password", "Restricted Form")
-
-
'Check to see if there is any entry made to input box, or if
-
'cancel button is pressed. If no entry made then exit sub.
-
-
If strPasswd = "" Or strPasswd = Empty Then
-
MsgBox "No Input Provided", vbInformation, "Required Data"
-
Exit Sub
-
End If
-
-
'If correct password is entered open Employees form
-
'If incorrect password entered give message and exit sub
-
-
If strPasswd = "Graham" Then
-
DoCmd.OpenForm "frmEmp", acNormal
-
Else
-
MsgBox "Sorry, you do not have access to this form", _
-
vbOKOnly, "Important Information"
-
Exit Sub
-
End If
-
End Sub
-
You will notice the line If
strPasswd = "Graham" Then . This contains the required password that will be required when attempting to open the form.
This can be changed to any password that you wish.
(Note: This information is originally from, and can be found at:
http://www.databasedev.co.uk/button_security.html)