Question : "The expression you entered as a query parameter producted this error"

I am getting run-time error 2471 saying that "The expression you entered as a query parameter producted this error: Kelly".  This occurs for the line below.  "Kelly" is the value of strTempLast.  Any ideas?

strCurrentLast = Nz(DLookup(strTempLast, "dbo_STUDENT_DIM", "[STU_LAST_NAME]='" & strTempLast & "' and  [STU_ID]=" & strTempID))
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
Private Sub yesButton_Click()
    Dim strCurrentID As String
    Dim strCurrentLast As String
    Dim strTempID As String
    Dim strTempLast As String
    
    strTempID = Forms![FRM_Main_Login_Students]![stuIDTextBox].Value
    strTempLast = Forms![FRM_Main_Login_Students]![lastNameTextBox].Value
    
    'Search for inputed values in dbo_STUDENT_DIM table.
    strCurrentID = Nz(DLookup(strTempID, "dbo_STUDENT_DIM", "[STU_ID]=" & strTempID))
    strCurrentLast = Nz(DLookup(strTempLast, "dbo_STUDENT_DIM", "[STU_LAST_NAME]='" & strTempLast & "' and  [STU_ID]=" & strTempID))
    
    'If input is not found in TBL_Students, give error message and return to main login screen
    If strCurrentID = -1 Or strCurrentLast = "" Then
        If MsgBox("The information you entered did not match any IWU student records.  Please try again.", _
        vbOKOnly, "Invalid Entry") = vbOK Then
            DoCmd.OpenForm "FRM_Main_Login_Students", acNormal
            DoCmd.Close acForm, "FRM_First_Time_Message_Students", acSaveNo
            Exit Sub
        End If

    'If input is found, add all user data into the fields of TBL_Students
    Else
        DoCmd.Close acForm, "FRM_First_Time_Message_Students", acSaveYes
        DoCmd.OpenForm "FRM_New_Student_Detail", acNormal, "", , , acWindowNormal
    End If
End Sub

Answer : "The expression you entered as a query parameter producted this error"

You most likely need to change this one also:

strCurrentID = Nz(DLookup(strTempID, "dbo_STUDENT_DIM", "[STU_ID]=" & strTempID))

The syntax for DLookup is:

DLookup(TheFieldYouWantToReturn, TheTableYouWantToLookIn, YourCriteria)
Random Solutions  
 
programming4us programming4us