Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The expression you entered as a query parameter produced this error: ' '

Status
Not open for further replies.

nytewing

MIS
Jun 13, 2014
3
NZ
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
 
Which line of code raises the error ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Im not sure as the error message is too vague.

There are multiple places where it could be happening. Its most likely one of the dlookups which involves the txtemplogin field. This one has me stumped, prior to me changing the if statements checking txtemplogin and txtpassword have been populated the error was there and threw up a type mismatch error, however there was no error code, so couldnt trace easily.
 
PHV, I have since stepped through line by line and the line(s) that throw the error are the

Application.TempVars.Add "CurrentUserName", DLookup("EmpName", "tblEmployees", "[EmpID]=" & Me.txtEmpLogin.Value)
Application.TempVars.Add "CurrentUserType", DLookup("EmpType", "tblEmployees", "[EmpID]=" & Me.txtEmpLogin)

 
Why not use the already populated UserName and UserLevel variables ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top