I have a password protecting a form when it opens. That part works, the problem is I get a error if the user hits the cancel button or the wrong password is given.
I get a run-time error '2501': The OpenForm action was canceled. The msgbox is opening before the error message opens.
The code for the password is:
I get a run-time error '2501': The OpenForm action was canceled. The msgbox is opening before the error message opens.
The code for the password is:
Code:
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Error_Handler
If StrComp(InputBox("Please enter the Password."), Forms![Passwords_frm].[TxtbxPass1], 0) <> 0 Then
Cancel = True
MsgBox "Wrong password.", vbInformation Or vbOKOnly, "Operation cancelled"
End If
Error_Handler_Exit:
On Error Resume Next
Exit Sub
Error_Handler:
MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
"Error Number: " & Err.Number & vbCrLf & _
"Error Source: Form_Open" & vbCrLf & _
"Error Description: " & Err.Description & _
Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
, vbOKOnly + vbCritical, "An Error has Occurred!"
Resume Error_Handler_Exit
End Sub