I have a few forms in my Access database that only a few team members should be using I wrote the following to password-protect those forms, but if you enter the wrong password or hit cancel on the pop-up, it will open the form anyway.
How can I prevent Access from loading the form unless you enter the correct password?
Private Sub Form_Load()
Dim strInput As String
Dim strMsg As String
Beep
strMsg = "This function requires a password." & vbCrLf & vbLf & "Please see your manager for assistance."
strInput = InputBox(Prompt:=strMsg, title:="Password:")
If strInput = "administrator" Then 'password is correct
DoCmd.OpenForm "AddNewRule"
Else 'password is incorrect
MsgBox "Incorrect Password!" & vbCrLf & vbLf & "Please see your manager for assistance", vbCritical, "Invalid Password"
Exit Sub
End If
End Sub