I’m trying to run the following code, but I’m getting a “Type mismatch” compile error on DLookUp.
DLookUp returns a value, right?
This code, to me, says: in the strSQL recordset, look for where the SKUS_ORDERED column equals curSKU2.
strSQL, temp, curSKU2 are all initialized as string type variables.
...
strSQL = "SELECT * FROM ORDER_DATA WHERE [ORDER]=" & curOrder
Dim temp As String
temp = DLookup("SKUS_ORDERED", db.OpenRecordset(strSQL), SKUS_ORDERED = curSKU2)
...
Where is the type mismatch?
Can anyone help me out?
EDIT:
...
Set fld_orders = rst_orders.Fields("ORDER")
curOrder = fld_orders.Value
Dim temp As String
temp = DLookup("SKUS_ORDERED", "ORDER_DATA", "SKUS_ORDERED = '" & curSKU2 & "' AND [ORDER] = " & curOrder)
If temp <> Null Then MsgBox temp
...
The entire code is pretty long but here’s a larger snippet of where curOrder is initialized, this is inside a nested loop, curSKU2 is initialized earlier outside the loop. Hope it helps.
The mismatch occurs because the second parameter needs to be a string, not a RecordSet.
If any of the parameters in the third argument is a variable (like in your case), the third argument needs to be a concatenated string as well:
EDIT:
Without more code, it’s difficult to see where you are using Null.
Are the table name and the column names correct?
What types are your variables? Do they really have values?
Can you post some more code where we can see how you declare and fill the variables?
The “_” character indicates a line break. I could have written the whole statement in one line, but then you’d have to scroll to see it completely:
EDIT 2:
Could you show the parts where both variables are declared and where curSKU2 is initialized as well? With what you posted, one still can’t see if curSKU2 is even filled and what types both are.
Plus,
tempis declared as string, so it can never be Null.This has two consequences:
If temp <> Nulldoesn’t make sense.temp = DLookup(...).Try
temp = Nz(DLookup(...))instead.