password protect a form

  • Thread starter Thread starter alicia
  • Start date Start date
Yes, you can. Here is one way you can do it. First create a table called
tblPassword. Create one field named ObjectName and set it to primary key.
This is a text field. Next create a field named KeyCode , this is also a
text field. The input mask needs to be Password and then you can under
default value use this expression.
="administrator" or whatever you want. Set validation rule to is not null
and you can enter a message for validation text such as You Must Enter a
Password.
Next Create a Form named frmPassword. Set the Caption to Type Your Password.
Create a textbox named Text0 and set its input mask to Password.
Next create a Command Button and set its Caption to Check Password. Under
Properties on the On Click use this code.
NOTICE that the form name it opens is Orders, you can change this to
whatever the forms name is you want to open.
Also the password here is set to administrator, you can change that as well.
Hope This Helps.

Dave
P.S. Set the code or macro to open this form first (frmPassword).When you
want to open the protected password form.

If IsNull(Forms!frmPassword!Text0.Value) Then
MsgBox "You cannot enter a blank Password. Try again."
Me!Text0.SetFocus


Else
End If

If (Forms!frmPassword!Text0 = "administrator") Then

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Orders"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, Me.Name



Else: MsgBox "Wrong Password, Try again."

End If
 
Back
Top