All pastes #1763368 Raw Edit

DLookup with multiple fields

public text v1 · immutable
#1763368 ·published 2010-01-23 23:01 UTC
rendered paste body
Dim CustID As String
Dim EmpID As Long
Dim Result
CustID = "SIMOB"
EmpID = 2
Result = DLookup("[OrderID]", "Orders", _
"[CustomerID] = '" & CustID & "' And [EmployeeID] = " & EmpID)
MsgBox Result
				

'NOTE:  If the DLookup() function is unsuccessful, the variable Result contains a null. 
'NOTE:  The criteria is made up of four pieces that are evaluated individually. 
'NOTE:  The results are appended, then evaluated as a whole.