Lookup function not working

J

jayC

I am creating customer invoices using a form bound to a query called
"Invoices Query". Invoices Query is bound to the "Customer Table".

I would like to use the Lookup function in a text box to automatically fill
in the billing date on the form for each customer.
I created a table called "DATATABLE" that has a field called IN DATE and a
field called BILLINGDATE. The "Invoices Query" query also contains a field
called IN DATE. The text box is supposed to show the data in the
BILLINGDATE field based on the corresponding data in the IN DATE field for
each customer.
This is what I inputed (Access automatically inserted brackets in some parts
of the statement):


=DLookUp("[BILLINGDATE]","[DATATABLE]","[IN DATE] =" & [Forms]![Invoices
Query]![IN DATE])

The above is returning #NAME? error when the First 10 RecordsPreview is
clicked.
 
K

Klatuu

You formatting of the criteria is for a numeric field. For a date field, you
need to use the # as delimiters:

=DLookUp("[BILLINGDATE]","[DATATABLE]","[IN DATE] = #" & [Forms]![Invoices
Query]![IN DATE]) & "#"

BTW IN DATE is not a good name. You should not use spaces in names.
 
J

jayC

"In Date" is a text field since I am using my own code. BILLINGDATE is
also a text field, though I could change it to a date field.
What would be the expression for a text field?

Thanks

Klatuu said:
You formatting of the criteria is for a numeric field. For a date field,
you
need to use the # as delimiters:

=DLookUp("[BILLINGDATE]","[DATATABLE]","[IN DATE] = #" & [Forms]![Invoices
Query]![IN DATE]) & "#"

BTW IN DATE is not a good name. You should not use spaces in names.


--
Dave Hargis, Microsoft Access MVP


jayC said:
I am creating customer invoices using a form bound to a query called
"Invoices Query". Invoices Query is bound to the "Customer Table".

I would like to use the Lookup function in a text box to automatically
fill
in the billing date on the form for each customer.
I created a table called "DATATABLE" that has a field called IN DATE and
a
field called BILLINGDATE. The "Invoices Query" query also contains a
field
called IN DATE. The text box is supposed to show the data in the
BILLINGDATE field based on the corresponding data in the IN DATE field
for
each customer.
This is what I inputed (Access automatically inserted brackets in some
parts
of the statement):


=DLookUp("[BILLINGDATE]","[DATATABLE]","[IN DATE] =" & [Forms]![Invoices
Query]![IN DATE])

The above is returning #NAME? error when the First 10 RecordsPreview is
clicked.
 

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