DLookup without criteria?

MangoFruit

Registered User.
Local time
Yesterday, 22:02
Joined
Feb 6, 2014
Messages
19
Hi all,

I've never used DLookup before and I can't get it to work for me so far.
I have 1 table which contains products and different properties of each product, such as the weight of the product.
I have created a query which sums the weight of all products, but only for those that have a value >0 in a certain field. This all works fine.
Now I simply want to display that calculated total weight in a text box on a form. So I thought DLookup could be used for that. But I can't get it to work, maybe because I'm not putting in any criteria? In the control source of the text box I've put the following:

=dlookup("[TotalWeight]","qryTotals")

I don't have any criteria, I just want the value from my qry expression. The textbox on my form now displays #name?

What am I doing wrong?
 
Thanks it worked! I still don't know why Dlookup didn't work but I learned something new and it gets the job done! :)
 
dlookup("[TotalWeight]","qryTotals")

this looks for a field called Totalweight in the query qryTotals. if your query is structured in that way, then it will work correctly. the error #name indicates the field was not found.


dsum("[TotalWeight]","qryTotals")

this adds together the values for the field TotalWeight in the query.

------

So it is a matter of choice which way you go,

------

The criteria expression in a dlookup/dsum is used to select particular item(s) from the full query.

so if your query "qryTotals" is a totals query, with a field called TotalWeight , but also has extra groupby columns (eg, a department), then opening the query will show you a number of possible items - ie a TotalWeight for each department

so the dlookup has to refine the search to select just the row you want

eg
dlookup("[TotalWeight]","qryTotals","department = 1")

The dsum works in a similar fashion.
 

Users who are viewing this thread

Back
Top Bottom