DLOOKUP & combo boxes

  • Thread starter Thread starter Jon B
  • Start date Start date
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.
 
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 #
 
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.
 
Back
Top