How to write DLookup

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In a form, I want to retrieve data from a table ATC Master, field ply with
the condition Article/Tkt of the table should match with Article_Tkt of the
form TransactionTable.

I have written as follows, and I am not getting any value...
DLookup("[ATC Master]![Ply]", "[ATC Master]", "[ATC Master]![Article/Tkt] =
Forms![Article_Tkt]")

Kindly help me.
 
First, you only need the name of the field in the first argument.
You don't need to bracket the table name.
In the last argument, the value you want to look for has to be outside the
quotes. What you are passing is the literal value "Forms![Article_Tkt]",
not the value in that control. Here is the correct syntax:

One other thing is whether the field Article_Tkt in ATC Master is a text or
numeric field. It will make a difference in the syntax.
If it is a numeric field:

DLookup("[Ply]", "ATC Master", "[Article/Tkt] = " & Forms![Article_Tkt])

If it is a text field:

DLookup("[Ply]", "ATC Master", "[Article/Tkt] = '" & Forms![Article_Tkt] &
"'")
 
DLookup doesn't know anything about controls on your form. You need to put
the reference to the control outside of the quotes. Also, remove the
reference to the table when referring to fields:

DLookup("[Ply]", "[ATC Master]", "[Article/Tkt] = " & Forms![Article_Tkt])

assuming field Article/Tkt is numeric, or

DLookup("[Ply]", "[ATC Master]", "[Article/Tkt] = " & Chr$(34) &
Forms![Article_Tkt] & Chr$(34))

if it's text.
 
Back
Top