Question : WHERE clause with DLookup

Could someone tell me the proper syntax for this line?  I want to look up a value in the table dbo_STUDENT_DIM in the STU_LAST_NAME field, but the strCurrentID variable must match the STU_ID field for that record.  In other words, I don't just want it to find that last name, as hundred of people could have that name.  I want the ID number to match as well.

 strCurrentLast = Nz(DLookup("LastName", "dbo_STUDENT_DIM", "STU_LAST_NAME="
& "LastName" WHERE strCurrentID = STU_ID))
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:
29:
30:
31:
32:
33:
34:
Private Sub Form_Activate()
           
    Dim strCurrentID As String
    Dim strCurrentLast As String
    
    STU_ID = Forms![FRM_Main_Login_Students]![stuIDTextBox].Value
    LastName = Forms![FRM_Main_Login_Students]![lastNameTextBox].Value
    
    
    'Search for inputed values in dbo_STUDENT_DIM table.
    strCurrentID = Nz(DLookup("STU_ID", "dbo_STUDENT_DIM", "[STU_ID]=" & "[STU_ID]"))
    strCurrentLast = Nz(DLookup("LastName", "dbo_STUDENT_DIM", "STU_LAST_NAME=" & "LastName" WHERE strCurrentID = STU_ID))
        
    '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.Close acForm, "FRM_New_Student_Detail", acSaveNo
           DoCmd.OpenForm "FRM_Main_Login_Students", acNormal
           Exit Sub
        End If
    'If input is found, add all user data into the fields of TBL_Students
    Else
         FirstName = STU_FIRST_NAME
         Middle = STU_MIDDLE_NAME
         LastName = STU_LAST_NAME
         Campus_Box = STU_CAMPUS_ADDR1
         Phone = STU_CELL_PHONE
         Email = STU_EMAIL
         Address = STU_ADDR1
         City = STU_CITY
         State_Abbreviation = STU_STATE
         Zip = STU_ZIP
    End If
End Sub

Answer : WHERE clause with DLookup



strCurrentLast = Nz(DLookup("LastName", "dbo_STUDENT_DIM", "STU_LAST_NAME='"
& LastName &"' and  [STU_ID]= " & STU_ID))
Random Solutions  
 
programming4us programming4us