the expression you entered as a query produced this error: 'jasonp'.
jasonp being the username entered into the txtEmpLogin field.
Private Sub cmdLogin_Click()
Dim User As String
Dim UserName As String
Dim UserLevel As Integer
Dim TempPass As String
Dim ID As Integer
Dim EmpLogin As String
Dim TempLoginID As String
Dim EmpID As Integer
On Error GoTo errorHandling
'Check to see if data is entered into the Login ID field
If IsNull(Me.txtEmpLogin) Or Me.txtEmpLogin = "" Then
MsgBox "You must enter your Login ID", vbOKOnly, "Login ID Required!"
Me.txtEmpLogin.SetFocus
ElseIf IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "You must enter your password", vbOKOnly, "Password Required!"
Me.txtPassword.SetFocus
Else
'Check value of password in tblEmployees to see if this matches value enterd in Login ID Field
If (IsNull(DLookup("EmpLogin", "tblEmployees", "EmpLogin = '" & Me.txtEmpLogin.Value + "' And EmpPassword = '" & Me.txtPassword & "'"))) Then
MsgBox "Incorrect Login ID or Password", vbOKOnly, "Incorrect Login ID or Password!"
Else
TempLoginID = Me.txtEmpLogin.Value
UserName = Nz(DLookup("[EmpName]", "tblEmployees", "[EmpLogin] = '" & Me.txtEmpLogin.Value & "'"))
UserLevel = (DLookup("[EmpType]", "tblEmployees", "[EmpLogin] = " & Me.txtEmpLogin.Value & ""))
TempPass = (DLookup("[EmpPassword]", "tblEmployees", "[EmpLogin] = '" & Me.txtEmpLogin.Value & "'"))
ID = (DLookup("[EmpID]", "tblEmployees", "[EmpLogin] = '" & Me.txtEmpLogin.Value & "'"))
If (TempPass = "12345") Then
MsgBox "Please change your password", vbInformation, "New Password Required"
DoCmd.OpenForm "frmChangePass", , , "[EmpID] = " & ID
Else
'Close login form and open splash screen
Application.TempVars.Add "CurrentUserName", DLookup("EmpName", "tblEmployees", "[EmpID]=" & Me.txtEmpLogin.Value)
Application.TempVars.Add "CurrentUserType", DLookup("EmpType", "tblEmployees", "[EmpID]=" & Me.txtEmpLogin)
DoCmd.Close acForm, "frmLogin", acSaveNo
If UserLevel = 1 Then 'for admin
MsgBox "Admin Access Granted"
ElseIf UserLvel = 2 Then 'for managers
MsgBox "Manager Access Granted"
ElseIf UserLevel = 3 Then 'for techs
MsgBox "Tech Access Granted"
Else
MsgBox "Read Only Access Granted"
'DoCmd.OpenForm "Mainfrm"
End If
End If
End If
End If
'If User enters incorrect password 3 times application will shutdown
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts >= 3 Then
MsgBox "You do not have access to this application. Please contact your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If
Exit Sub
errorHandling:
MsgBox Err.Description
End Sub
Above is the code I have, I originally had the field as a combo box, but decided I prefer for security reasons to have users type in their Login Name.
Can anyone please help, as I can see what works and what doesn't, but its not clear as to why this happens.
Cheers
jasonp being the username entered into the txtEmpLogin field.
Private Sub cmdLogin_Click()
Dim User As String
Dim UserName As String
Dim UserLevel As Integer
Dim TempPass As String
Dim ID As Integer
Dim EmpLogin As String
Dim TempLoginID As String
Dim EmpID As Integer
On Error GoTo errorHandling
'Check to see if data is entered into the Login ID field
If IsNull(Me.txtEmpLogin) Or Me.txtEmpLogin = "" Then
MsgBox "You must enter your Login ID", vbOKOnly, "Login ID Required!"
Me.txtEmpLogin.SetFocus
ElseIf IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "You must enter your password", vbOKOnly, "Password Required!"
Me.txtPassword.SetFocus
Else
'Check value of password in tblEmployees to see if this matches value enterd in Login ID Field
If (IsNull(DLookup("EmpLogin", "tblEmployees", "EmpLogin = '" & Me.txtEmpLogin.Value + "' And EmpPassword = '" & Me.txtPassword & "'"))) Then
MsgBox "Incorrect Login ID or Password", vbOKOnly, "Incorrect Login ID or Password!"
Else
TempLoginID = Me.txtEmpLogin.Value
UserName = Nz(DLookup("[EmpName]", "tblEmployees", "[EmpLogin] = '" & Me.txtEmpLogin.Value & "'"))
UserLevel = (DLookup("[EmpType]", "tblEmployees", "[EmpLogin] = " & Me.txtEmpLogin.Value & ""))
TempPass = (DLookup("[EmpPassword]", "tblEmployees", "[EmpLogin] = '" & Me.txtEmpLogin.Value & "'"))
ID = (DLookup("[EmpID]", "tblEmployees", "[EmpLogin] = '" & Me.txtEmpLogin.Value & "'"))
If (TempPass = "12345") Then
MsgBox "Please change your password", vbInformation, "New Password Required"
DoCmd.OpenForm "frmChangePass", , , "[EmpID] = " & ID
Else
'Close login form and open splash screen
Application.TempVars.Add "CurrentUserName", DLookup("EmpName", "tblEmployees", "[EmpID]=" & Me.txtEmpLogin.Value)
Application.TempVars.Add "CurrentUserType", DLookup("EmpType", "tblEmployees", "[EmpID]=" & Me.txtEmpLogin)
DoCmd.Close acForm, "frmLogin", acSaveNo
If UserLevel = 1 Then 'for admin
MsgBox "Admin Access Granted"
ElseIf UserLvel = 2 Then 'for managers
MsgBox "Manager Access Granted"
ElseIf UserLevel = 3 Then 'for techs
MsgBox "Tech Access Granted"
Else
MsgBox "Read Only Access Granted"
'DoCmd.OpenForm "Mainfrm"
End If
End If
End If
End If
'If User enters incorrect password 3 times application will shutdown
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts >= 3 Then
MsgBox "You do not have access to this application. Please contact your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If
Exit Sub
errorHandling:
MsgBox Err.Description
End Sub
Above is the code I have, I originally had the field as a combo box, but decided I prefer for security reasons to have users type in their Login Name.
Can anyone please help, as I can see what works and what doesn't, but its not clear as to why this happens.
Cheers