DLookup getting error

rdshag

New member
Local time
Today, 09:30
Joined
Mar 4, 2016
Messages
8
I have two Query,
1. Open item query - this is were I what to run dlookup, and the Expr2 is the field that I want looked up.
2. location query - has what I an looking for

if expr2 = [location query]![location] then give me what is in column [location query]![l-pre]

this is the equation that I am using in access

DLookUp("[Location Query]![LOCATION]",[Expr2],"[Location Query]![L-PRE] = '[Expr2]'")

I am trying to do what I did in excel
=LOOKUP(AF160417,Location!A:A,Location!B:B)


thank Duncan
 
Last edited:
You have the syntax incorrect

DLookup("Your Field Name","Your table or Query Name","[CriteriaField] = '" & Expr2 & "'")

This assumes
1. That Expr2 is text
2. Expr2 is not a calculated field .
Which by the very name of it I suspect it is.

Don't put square brackets around the field or query names.
 
DLookup parameters should be in the form

DLookup( expr, domain [, criteria] )

where expr is normally a field name and domain is table or query. Your dlookup doesn't seem to be in that format.

See DLookUp
 
You have the syntax incorrect

DLookup("Your Field Name","Your table or Query Name","[CriteriaField] = '" & Expr2 & "'")

This assumes
1. That Expr2 is text
2. Expr2 is not a calculated field .
Which by the very name of it I suspect it is.

Don't put square brackets around the field or query names.

I think Minty means not to put square brackets around the field or query names if they don't have spaces in them. If you actually have a field named "Your Field Name" and a table or query named "Your table or Query Name" the DLookup would have to be:

DLookup("[Your Field Name]","[Your table or Query Name]","[CriteriaField] = '" & Expr2 & "'")

or you will get syntax errors.

Also if you like to live on the edge and use reserve names like Date for field names then those too should be in brackets.
 
Last edited:
I am trying to do what I did in excel
=LOOKUP(AF160417,Location!A:A,Location!B:B)
 
Maybe

Code:
DLookUp("[LOCATION]","[Location Query]", "[L-PRE] = '" & Expr2 & "'")

This assumes Expr2 is a string with a value assigned to it and that L-PRE is a text field.
 

Users who are viewing this thread

Back
Top Bottom