Avatar of thandel
thandel
 asked on

DLookup in report text box

Trying to get a report to use dlookup based on a value on a form (fReportSelect) in the drop down field of LocSelect.

In my report I have the following in a text box:

=DLookUp("Abr","tOffice","Office = " & "'" & ([Forms]![FReportSelect]![LocSelect]) & "'")


But it's not pulling up values from table tOffice.

What is wrong with my syntax?
Microsoft Access

Avatar of undefined
Last Comment
thandel

8/22/2022 - Mon
PatHartman

What is the value of ([Forms]![FReportSelect]![LocSelect]) ?
Does it exist as a value of Office in tOffice?
Is the confusion caused because of a table level lookup?
thandel

ASKER
It's a text value and yes its matches up with the values in the table (the drop down list gets the value from the table I'm dlooking up with.
PatHartman

Is the other report open?  The implication of your syntax is that some form or report is referencing a different form or report.  Otherwise, the syntax would be:
 
=DLookUp("Abr","tOffice","Office = " & """ & LocSelect & "'")

You might also be missing quotes:

=DLookUp("Abr","tOffice","Office = " & """" & LocSelect & ""'")
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
thandel

ASKER
It's a form and yes the form is open.... I tried both your suggestions but I get an error "The expression you entered has an invalid string"
bfuchs

try this

=DLookUp("Abr","tOffice","Office = " & "'" & ([Forms]![FReportSelect].[LocSelect]) & "'")

Open in new window

or
=DLookUp("Abr","tOffice","Office = " & "'" & [Forms]![FReportSelect].[LocSelect] & "'")

Open in new window

thandel

ASKER
Odd no errors but nothing is displaying.    If I use just [Forms]![FReportSelect].[LocSelect] it works OK to display the value from the drop down list on the form.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
bfuchs

are you sure there are none null values on the table?
what happens when you try the actual value in debug window?
thandel

ASKER
nope no null values.  Not sure how to the value in the debug in window - sorry
bfuchs

?DLookUp("Abr","tOffice","Office = " & "'" & PutTheValueOnFormHere & "'")
and press enter
Your help has saved me hundreds of hours of internet surfing.
fblack61
thandel

ASKER
Where do I type that in to?
thandel

ASKER
I think in the Immediate window?

I did that and go the following error:

"Compile error, expected: list separator or )"
bfuchs

in code look for the immediate window.
or you can also type that in any query
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
bfuchs

what did you you type, post the value
thandel

ASKER
?DLookUp("Abr","tOffice","Office = " & "'" & Central Square & "'")
thandel

ASKER
IF I do this ?[Forms]![FReportSelect]![LocSelect] I get the correct value on the form
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
thandel

ASKER
Seems to be some sort of issue with dlookup
ASKER CERTIFIED SOLUTION
bfuchs

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
thandel

ASKER
That worked
thandel

ASKER
so ?DLookUp("Abr","tOffice","Office = '" & [Forms]![FReportSelect]![LocSelect] & "'") works!
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
thandel

ASKER
Got it now and I learned about the debug window! Thanks!