DLOOKUP & combo boxes

J

Jon B

I am trying to use a DLOOKUP with the criteria being the contents of a
combo box. It works fine if the criteria relates to column(0) but I
cannot get it to work for any other column.

Normally, DLOOKUP("[Field]", "Table",
"[Field]=[forms]![formname]![cboName]") is OK, but not if the criteria
is [Field]=[forms]![formname]![cboName.column(2)]

I have tried other bracketing options, but no luck. What is the
correct syntax please?

Thanks.
 
D

Dan Artuso

Hi,
What is the data type of column 2?
If it's text (string) you have to delimit with single quotes:
DLOOKUP("[Field]", "Table", "[Field]='" & [forms]![formname]![cboName.column(2)] & "'")
If it's a date, change the delimiter to #
 
S

Sandra Daigle

Have you tried appending the value - the way you have it you are passing a
reference to the control.

DLOOKUP("[Field]", "Table","[Field]=" &
[forms]![formname]![cboName].column(2))

Note that the control reference is outside the quotes and is appended to the
"Field=" string. This allows VBA to resolve the reference to the column
property of the control.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top