Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Dlookup function

0 views
Skip to first unread message

Coco111 via AccessMonster.com

unread,
Dec 20, 2009, 4:47:42 AM12/20/09
to
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.

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-gettingstarted/200912/1

Coco111 via AccessMonster.com

unread,
Dec 20, 2009, 4:47:31 AM12/20/09
to
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.

--
Message posted via http://www.accessmonster.com

Rick Brandt

unread,
Dec 20, 2009, 8:05:15 AM12/20/09
to
Coco111 via AccessMonster.com wrote:

> 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)

Coco111 via AccessMonster.com

unread,
Dec 20, 2009, 8:44:03 AM12/20/09
to
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 Brandt wrote:
>> 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)

--

Rick Brandt

unread,
Dec 20, 2009, 9:19:49 AM12/20/09
to
Coco111 via AccessMonster.com wrote:

> 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.

John Spencer

unread,
Dec 20, 2009, 9:16:39 AM12/20/09
to
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

Coco111 via AccessMonster.com

unread,
Dec 20, 2009, 10:00:24 AM12/20/09
to
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 Spencer wrote:
>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,
>>
>[quoted text clipped - 24 lines]


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

--

Coco111 via AccessMonster.com

unread,
Dec 20, 2009, 10:06:25 AM12/20/09
to
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 Brandt

unread,
Dec 20, 2009, 12:15:03 PM12/20/09
to
Coco111 via AccessMonster.com wrote:

> 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?


KenSheridan via AccessMonster.com

unread,
Dec 20, 2009, 1:22:09 PM12/20/09
to
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

Coco111 wrote:
>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.
>

>>> Hi,
>>>
>[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.

--
Message posted via http://www.accessmonster.com

bhicks11 via AccessMonster.com

unread,
Dec 20, 2009, 6:16:05 PM12/20/09
to
It looks like you didn't give any criteria to look up. You have ID but not
what ID must equal to find the correct record.

Bonnie
http://www.dataplus-svc.com

Coco111 via AccessMonster.com

unread,
Dec 20, 2009, 7:58:37 PM12/20/09
to
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

--

0 new messages