Dlookup doesnt work; complete Details included

  • Thread starter Thread starter tom
  • Start date Start date
T

tom

The following control works fine

=[Forms]![form1]![invoice number]

The following control does not work nor any of its permutations that I can
figure

=DLookUp("[supplier name]","00query1","[other number] =" &
[Forms]![form1]![invoice number])


The following control will work.

=DLookUp("[supplier name]","00query1","[other number] ='6691'")

but of course that is not at all what I want.
 
Your working hardcoded example has quotes around the value: you need those
in the non-hardcoded example as well.

=DLookUp("[supplier name]","00query1","[other number] ='" &
[Forms]![form1]![invoice number] & "'")

Exagerated for clarity, that 3rd parameter is

"[other number] = ' " & [Forms]![form1]![invoice number] & " ' "
 
The following control works fine

=[Forms]![form1]![invoice number]

The following control does not work nor any of its permutations that I can
figure

=DLookUp("[supplier name]","00query1","[other number] =" &
[Forms]![form1]![invoice number])


The following control will work.

=DLookUp("[supplier name]","00query1","[other number] ='6691'")

but of course that is not at all what I want.

Evidently [other number] is of Text datatype; therefore you need the
quotemark delimiters. Try

=DLookUp("[supplier name]","00query1","[other number] ='" &
[Forms]![form1]![invoice number] & "'")

John W. Vinson[MVP]
 
Thank you, I am confused by the &, What is the
rule for these?


Douglas J. Steele said:
Your working hardcoded example has quotes around the value: you need those
in the non-hardcoded example as well.

=DLookUp("[supplier name]","00query1","[other number] ='" &
[Forms]![form1]![invoice number] & "'")

Exagerated for clarity, that 3rd parameter is

"[other number] = ' " & [Forms]![form1]![invoice number] & " ' "


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


tom said:
The following control works fine

=[Forms]![form1]![invoice number]

The following control does not work nor any of its permutations that I can
figure

=DLookUp("[supplier name]","00query1","[other number] =" &
[Forms]![form1]![invoice number])


The following control will work.

=DLookUp("[supplier name]","00query1","[other number] ='6691'")

but of course that is not at all what I want.
 
& is a String concatenator operator combining 2 String operands. For
example, the expression:

"This " & "is " & "the " & "whole " & "sentence."

will result in the String.

"This is the whole sentence."

(without the double quotes).
 
Thank you, though I still am not clear on why
they are needed in the dlookup criteria.
 
tom said:
Thank you, though I still am not clear on why
they are needed in the dlookup criteria.

Because you (usually) do not want the form control references inside the
quotes.
 
Basically, the criteria (3rd) argument of the DLookUp() function is a String
(that specifies your selection criteria. Thus, what you need in the end
is:, for example:

"[other number] = '6691'"

(without the double quotes, assuming that [Forms]![form1]![invoice number]
has the entry "6691". The single quotes above indicates that it a String
value, the same data type as the Field [other number]).

To get the above, i.e. including the single-quotes in your criteria argument
using the String concatenation, you need to use:

"[other number] ='" & [Forms]![form1]![invoice number] & "'"

when Access evaluates the above expression, it will replace the reference
[Forms]![form1]![invoice number] with the String value "6691" (without the
double-quotes) and the single quotes are considered as literals to be
included in the result (because the single quotes are inside the String
delimiter "). The double-quotes are all "consumed" by the concatenation
process and thus, the result of the concatenation is:

"[other number] = '6691'"

(without the double quotes) and it is the correct input for the criteria
argument of the DLookUp() function.
 

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

Similar Threads

DLookUp behavior 1
DLookup function problem 3
DLookup Function 2
Bound a DLookUp Value 2
Access 2010 Dlookup problem 0
Blank Fields in Report 2
DLookup help 6
DLookup in Text box to show Currency (number field) 9

Back
Top