can anyboby assist me on this errer. Please see code below. I am new to programming so amonly learning the basics. Thanks in advance.
Private Sub cmd_Login_Click()
On Error GoTo ErrorHandler:
'Check if data is entered in the Username textbox
If IsNull(txtUsername) Or Me.txtUsername = "" Then
MsgBox "Username is required", vbOKOnly, "Invalid Entry!"
txtUsername.SetFocus
Exit Sub
'Check if data is entered in the Password textbox
ElseIf IsNull(txtPassword) Or Me.txtPassword = "" Then
MsgBox "Password is required", vbOKOnly, "Invalid Entry!"
txtPassword.SetFocus
Exit Sub
Else
Dim response As String
Dim strPass As String
strPass = DLookup("Password", "tblUser", "[EmployeeID]='" & Me.txtUsername & "'") & ""
If strPass = "" Then
'No match was found for username
MsgBox "Username doesn't exist! Please try again.", vbOKOnly, "Invalid Username!"
intLogAttempt = intLogAttempt + 1
txtUsername.SetFocus
ElseIf strPass <> txtPassword Then
'Password does not match
MsgBox "Invalid Password!", vbOKOnly, "Invalid Password!"
intLogAttempt = intLogAttempt + 1
txtPassword.SetFocus
End If
'If the user enters incorrect password and username for 3 times database will shutdown
If intLogAttempt = 3 Then
MsgBox "You do not have access to this database.Please contact admin." & vbCrLf & vbCrLf & _
"Application will exit.", vbCritical, "Restricted Access!"
Application.Quit
End If
End If
'Username and password are correct, system will open the Main page
strUser = Me.txtUsername 'Set the value of the strUser declared as Global variable to be displayed in the main page
strRole = DLookup("Role", "tblUser", "[EmployeeID]='" & Me.txtUsername & "'") 'Set the value of the strRole declared as Global variable to be displayed in the main page
DoCmd.Close acForm, "frmUserLogin", acSaveNo
MsgBox "Welcome to MainPage! " & strUser, vbOKOnly, "Welcome!"
'Close login form and open Main page
DoCmd.OpenForm "frmMainPage", acNormal, "", "", , acNormal
ErrorHandler: MsgBox "An unexpected error has occured. Please contact an administrator" & vbNewLine & _
Err.Number & " - " & Err.Description, vbOKOnly + vbCritical, "Critical Error"
End Sub