user3565178
user3565178

Reputation: 5

Access Form Dlookup - Using a Combo box for the expression value

Good Morning,

I am doing some work for a colleague and he wants a form creating where he can change to column that is looked at through a combo box as well as the criteria

I have tried the following

=DLookUp(" & [Combo8] & ","Product Guidelines","PC =  '" & [Combo2] & "'")

but get an error, if i hard code the expression to one of the columns it works fine but when it's set to look at the combo box it doesn't work, I have tried several variants of the code but have no ran out of ideas

Please can someone help

Thank you

Upvotes: 0

Views: 993

Answers (2)

Gustav
Gustav

Reputation: 55831

The syntax would be:

=DLookUp("[FieldNameToLookUp]","[Product Guidelines]","PC = '" & Me![Combo2] & "'")

as you probably don't have a field named Combo8.

If Combo8 holds that name, it would be:

=DLookUp("[" & Me!Combo8 & "]","[Product Guidelines]","PC = '" & Me![Combo2] & "'")

Upvotes: 1

Andre
Andre

Reputation: 27634

Look closely at your code. You are passing the literal string " & [Combo8] & " (including spaces and ampersands) as first parameter to DLookup.

Try

=DLookUp([Combo8], "Product Guidelines", "PC = '" & [Combo2] & "'")

or if the content of Combo8 has spaces,

=DLookUp("[" & [Combo8] & "]", "Product Guidelines", "PC = '" & [Combo2] & "'")

or maybe even with quotes around it:

=DLookUp("""[" & [Combo8] & "]""", "Product Guidelines", "PC = '" & [Combo2] & "'")

Upvotes: 1

Related Questions