Link to home
Start Free TrialLog in
Avatar of shawnkimble
shawnkimbleFlag for United States of America

asked on

Multiple Criteria Dlookup Syntax in Access Query

I have the following two criteria needed in a Dlookup.  The below syntax works correctly but returns the incorrect answer because I cannot figure out how to properly put both criteria in one statement.  

In case its hard to see, In the second statement there are single quotes around BillPaymentCheck.

Expr2: DLookUp("TxnDate","linkedtxndetail",[linkedtxndetail]![IDKEY]=[Bill]![TxnID])
Expr2: DLookUp("TxnDate","linkedtxndetail","[linkedtxndetail]![TxnType]='BillPaymentCheck'")
Avatar of omgang
omgang
Flag of United States of America image

Expr2: DLookUp("TxnDate","linkedtxndetail",[IDKEY]=[Bill]![TxnID] AND [TxnType]='BillPaymentCheck'"))

OM Gang
ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shawnkimble

ASKER

Ah, the old Chr(34).  Thanks!

Expr2: DLookUp("TxnDate","linkedtxndetail","[linkedtxndetail]![IDKEY]= " & Chr(34) & [Bill]![TxnID] & Chr(34) & " AND " & "[linkedtxndetail]![TxnType] = " & Chr(34) & "BillPaymentCheck" & Chr(34))
I use Chr(34) for clarity of posting - like ... how many double quotes do you see here:

'""'""

:-)

thx.mx
Freakin' amazing!  That's the second time in a couple of weeks you've gotten the points on a Q for essentially the exact same answer I posted first.

shawnkimble states
"The below syntax works correctly..."
I provided an solution to the specific question he asked
"...because I cannot figure out how to properly put both criteria in one statement"

The first criteria on [TxnID] should be numeric because he stated the syntax worked correctly.  The use of single apostrophe's was in his original example.  The solution is to use an 'AND' statement to specify multiple cirteria.

I am impressed.  It must be a personality thing 'mx.....I think people just like you better.  Or perhaps I should shower more often.

OM Gang
"essentially the exact same answer I posted first."

Well ... I hate to say this, but ... you missed some double quotes here:

Expr2: DLookUp("TxnDate","linkedtxndetail",[IDKEY]=[Bill]![TxnID] AND [TxnType]='BillPaymentCheck'"))

mx
                                                                 ----^                                     --^  
I missed one double quote (the second).  As I stated, shawnkimble indicated the syntax he provided worked correctly - since he used no double quotes in the first example it was not for me to add them.  One could also argue that you inserted Chr(34) where inappropriate - If [TxnID] is numeric it should not be enclosed in quotes.

Understand that I am not upset with you 'mx - simple frustration with how answers are accepted, i.e.

how do if fix this specific problem?
Answer1 = here's the solution
Answer2 = here's the solution and by the way your shoes are untied

Answer2 accepted - thanks! I could have tripped!

OM Gang
Perhaps from now on I should include a recipe for low-fat brownies with each solution - you know, a value-added kind of thing.
I think you missed more than one ...

mx