Dlookup function

  • Thread starter Coco111 via AccessMonster.com
  • Start date
C

Coco111 via AccessMonster.com

Hi, I try to get the value of "Net_Weight" from "Products" table and my
DlookUp function key as this =DLookUp("[Net_Weight]","Products","[ID]")

I got the valued, but it fix valued from the first field of "Products" table,
it did not changed accordingly to each product. Different product has
different weight which specific in "Products" table. How can I fix this,
function might be wrong somewhere? Please help. Thanks.
 
R

Rick Brandt

Coco111 said:
Hi, I try to get the value of "Net_Weight" from "Products" table and my
DlookUp function key as this =DLookUp("[Net_Weight]","Products","[ID]")

I got the valued, but it fix valued from the first field of "Products"
table, it did not changed accordingly to each product. Different product
has
different weight which specific in "Products" table. How can I fix this,
function might be wrong somewhere? Please help. Thanks.

The final argument needs to be the same as a WHERE clause in a query (only
without the word "WHERE"). Does this query makes sense?

SELECT Net_Weight
FROM Products
WHERE ID

You need to specify something about ID like...

SELECT Net_Weight
FROM Products
WHERE ID = 1234

If you are using this DLookup() on a form and you want the value where ID
matches a field named ID on the form then try...

=DLookUp("[Net_Weight]","Products","[ID] = " & Me.ID)
 
C

Coco111 via AccessMonster.com

Hi,

Yes, I use it on the form, I did try out =DLookUp("[Net_Weight]","Products","
[ID] = " & Me.ID), but it still did not work. Error message shows #Name?
Thanks.


Rick said:
Hi, I try to get the value of "Net_Weight" from "Products" table and my
DlookUp function key as this =DLookUp("[Net_Weight]","Products","[ID]")
[quoted text clipped - 4 lines]
different weight which specific in "Products" table. How can I fix this,
function might be wrong somewhere? Please help. Thanks.

The final argument needs to be the same as a WHERE clause in a query (only
without the word "WHERE"). Does this query makes sense?

SELECT Net_Weight
FROM Products
WHERE ID

You need to specify something about ID like...

SELECT Net_Weight
FROM Products
WHERE ID = 1234

If you are using this DLookup() on a form and you want the value where ID
matches a field named ID on the form then try...

=DLookUp("[Net_Weight]","Products","[ID] = " & Me.ID)
 
J

John Spencer

If ID is a number value then
=DLookUp("[Net_Weight]","Products","[ID] = " & Me.ID)
is the correct expression to assign to a control.

If ID is a text field then
=DLookUp("[Net_Weight]","Products","[ID] = """ & Me.ID & """")
is the correct expression to assign to a control.

If you are trying to use this in a query then you would need to drop the
equals sign at the start of the expression.

If Me.ID is null and the ID field is a number field then you might need
=DLookUp("[Net_Weight]","Products","[ID] = " & Nz(Me.ID,0))

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
Hi,

Yes, I use it on the form, I did try out =DLookUp("[Net_Weight]","Products","
[ID] = " & Me.ID), but it still did not work. Error message shows #Name?
Thanks.


Rick said:
Hi, I try to get the value of "Net_Weight" from "Products" table and my
DlookUp function key as this =DLookUp("[Net_Weight]","Products","[ID]")
[quoted text clipped - 4 lines]
different weight which specific in "Products" table. How can I fix this,
function might be wrong somewhere? Please help. Thanks.
The final argument needs to be the same as a WHERE clause in a query (only
without the word "WHERE"). Does this query makes sense?

SELECT Net_Weight
FROM Products
WHERE ID

You need to specify something about ID like...

SELECT Net_Weight
FROM Products
WHERE ID = 1234

If you are using this DLookup() on a form and you want the value where ID
matches a field named ID on the form then try...

=DLookUp("[Net_Weight]","Products","[ID] = " & Me.ID)
 
R

Rick Brandt

Coco111 said:
Hi,

Yes, I use it on the form, I did try out
=DLookUp("[Net_Weight]","Products","
[ID] = " & Me.ID), but it still did not work. Error message shows #Name?
Thanks.

Does your form have a control or bound field named "ID"?

What is the name of the control you are putting the DLookup() expresson in?
It cannot be the same as any of the operands in your expression.
 
C

Coco111 via AccessMonster.com

Hi John,

Table "Products" ID is a number value not text. I did try all the suggested
expression but it still cant solve the problem... What should I do? Thanks..

John said:
If ID is a number value then
=DLookUp("[Net_Weight]","Products","[ID] = " & Me.ID)
is the correct expression to assign to a control.

If ID is a text field then
=DLookUp("[Net_Weight]","Products","[ID] = """ & Me.ID & """")
is the correct expression to assign to a control.

If you are trying to use this in a query then you would need to drop the
equals sign at the start of the expression.

If Me.ID is null and the ID field is a number field then you might need
=DLookUp("[Net_Weight]","Products","[ID] = " & Nz(Me.ID,0))

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
[quoted text clipped - 24 lines]
=DLookUp("[Net_Weight]","Products","[ID] = " & Me.ID)
 
C

Coco111 via AccessMonster.com

No. I dont have any name "ID" in form. "Nett Wt" is the name of the field
that I want DLookup to fill in the value.

Rick said:
Hi,

Yes, I use it on the form, I did try out
=DLookUp("[Net_Weight]","Products","
[ID] = " & Me.ID), but it still did not work. Error message shows #Name?
Thanks.

Does your form have a control or bound field named "ID"?

What is the name of the control you are putting the DLookup() expresson in?
It cannot be the same as any of the operands in your expression.
 
R

Rick Brandt

Coco111 said:
No. I dont have any name "ID" in form. "Nett Wt" is the name of the field
that I want DLookup to fill in the value.

Yes, but what field or control on the form can be used in the WHERE clause?

You have a table with multiple rows and you have to specify to the DLookup()
function which row you want to pull the value from. That is the purpose of
the third argument. You need to tell the function which ID value in the
table specifies the row you want it pull the Nett Wt from.

Is there something on your form that can provide that information?
 
K

KenSheridan via AccessMonster.com

It sounds as though you do have an ID column in the underlying table, even if
not shown in the form. For the ControlSource of a text box take out the Me.
That's only used in VBA, so use:

=DLookUp("[Net_Weight]","Products","[ID] = " & [ID])

where ID is the name of the Products table's primary key column, and the name
of the corresponding foreign key column in the form's underlying table.

Ken Sheridan
Stafford, England
No. I dont have any name "ID" in form. "Nett Wt" is the name of the field
that I want DLookup to fill in the value.
[quoted text clipped - 7 lines]
What is the name of the control you are putting the DLookup() expresson in?
It cannot be the same as any of the operands in your expression.
 
C

Coco111 via AccessMonster.com

Hi all,

Thanks for your all effort and guide along.

I got it. In my form the name "Product ID" is the specific the row that want
as below criteria.
=DLookUp("[Net_Weight]","Products","[ID] = " & [Product ID])

Thanks so much....coco
 

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