PDA

View Full Version : dlookup multiple fields -'Run-time error '13'



Grega
07-01-2020, 09:06 AM
Hi,

I know that a lot about Dlookup has been written, but I struggle to compile a code with two criteria.
Example, these two codes work separately just fine.

DebitF = DLookup("Credit", "qryGeneralLedger", "CustCodeF = " & CustCode)
DebitF = DLookup("Credit", "qryGeneralLedger", "ReferF = '" & Refer & "' ")

However I want to put both two criteria in once code something like the one shown below with reported Error 'Run-time error '13':

DebitF = DLookup("Credit", "qryGeneralLedger", "CustCodeF = " & CustCode And "ReferF = '" & Refer & "' ")


Just to add note:
Cust code is Numeric value
Refer is text value

Thanks in advance for help!

Grega
07-02-2020, 02:30 AM
I got this figured out. If anyone is interested in how I solved this:

First, I changed the order for the individual codes. The order in the creiteria is very important!

This is the correct code for both individually:

DebitF = DLookup ("Credit", "qryGeneralLedger", "CustCode =" & CustCodeF)
DebitF = DLookup ("Credit", "qrygeneralLedger", "Refer = '" & ReferF & "'")


And this is then one code that considers both conditions together:

DebitF = DLookup ("Credit", "qryGeneralLedger", "CustCode =" & CustCodeF & "AND Refer = '" & ReferF & "'")