Open Form with Password

billgyrotech

Banned
Local time
Today, 06:29
Joined
Apr 18, 2013
Messages
258
I have a form protected with a password to open it. It prompts for a password but opens no matter what is entered. What am I missing?

Private Sub Form_Load()
Dim PassWord As String
PassWord = InputBox("Enter Administrator Password")
If PassWord = "password" Then
DoCmd.OpenForm "RecordStatus"
Else
MsgBox ("You're not authorized for Administrator access.")
End If
End Sub

Thanks,
Bill
 
This is in the load event of what form? If it's that one, it shouldn't be there.
 
You forget to close it if the password not matches. :)
 
Is this correct?

Private Sub Form_Load()
Dim PassWord As String
PassWord = InputBox("Enter Administrator Password")
If PassWord = "password" Then
DoCmd.OpenForm "RecordStatus"
Else
MsgBox ("You're not authorized for Administrator access.")
DoCmd.CloseForm "RecordStatus"
End If
End Sub
 
In the Form_Open method of "RecordStatus" ...

Code:
Private Sub Form_Open(Cancel as Integer)
  Dim PassWord As String

  PassWord = InputBox("Enter Administrator Password")
  Cancel = ( PassWord <> "password")

  If Cancel Then MsgBox ("You're not authorized for Administrator access.")
End Sub
 
Yes, your new code should do the trick, but Nigel's is more elegant.
 
You could probably use something similar for your Checkbox question as well.

Code:
Private Sub yourCheckBox_BeforeUpdate(Cancel as Integer)
  Dim PassWord As String

  PassWord = InputBox("Enter Administrator Password")
  Cancel = ( PassWord <> "password")

  If Cancel Then MsgBox ("You're not authorized to change this.")
End Sub
 

Users who are viewing this thread

Back
Top Bottom