Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using DLookup with multiple criteria

Status
Not open for further replies.

cratho

MIS
Mar 1, 2002
9
0
0
US
Is it possible to use the DLookup function in a report with more than one criteria? For example, DLookup("[Amount]", "tblSales", "[Year]= 2002 AND [SaleCD]=1"

I keep getting error messages. Thanks!
 
What error Message are you getting??

There are two ways to write error-free programs; only the third one works.
 
#Error

I just wanted to make sure it is possible before I try to debug it. It is quite possible that I have the syntax wrong.
 
Couple of observations:

Put both criteria in own quotes like:

DLookup("[Amount]", "tblSales", "[Year]= 2002" AND "[SaleCD]=1"

Add closing parenthesis to entire function like:

DLookup("[Amount]", "tblSales", "[Year]= 2002" AND "[SaleCD]=1")

if the year is a string, then you need to add the single quotes:

DLookup("[Amount]", "tblSales", "[Year]= & '2002'" AND "[SaleCD]=1")



 
Yes it is possible.

I would agree with Beeps second point but not the first

eg. this works fine on my db

strDLookUp = DLookup("Name", "tblName", "Age = 10 AND NameID = 7")

There are two ways to write error-free programs; only the third one works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top