I have a global login function on several Form Open events that require the input of a password and if the password is incorrect, it will Cancel the open event. The function works fine but if the event is canceled, it throws an error; runtime '2501'. How do I prevent this error from occurring? I've tried the On Error GoTo Next but that didn't prevent it. Any help would be greatly appreciated
Code:
Public Function IsAdmin() As Boolean
Dim AdminPass As String
Dim MyPass As String
MyPass = InputBox("Admin Level Security" & vbNewLine & "Enter Password")
AdminPass = DLookup("AdminPassword", "SettingT")
IsAdmin = False
If AdminPass = MyPass Then
IsAdmin = True
Else
IsAdmin = False
MsgBox "Incorrect Password!", vbExclamation
End If
End Function
Code:
Private Sub Form_Open(Cancel As Integer)
If IsAdmin = False Then
Cancel = True
Exit Sub
End If
End Sub