By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,615 Members | 1,961 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,615 IT Pros & Developers. It's quick & easy.

Dlookup issue

P: 5
Hello,

I am trying to seto up a Dlookup in a query.

My Dlookup field will retrieve data from a second query. The match criteria is the W field. This dlookup up process has to retrieve 24 different values from the second query (Query5). Unfortunatelly the function always brings the first value of the 2nd query for all the 24 fields.

My formula is the
Expr10: IIf([ph4]="Stock4";dLookUp("SumOfExpr2";"Query5";"[W]=" & "[Query5].[W]");[SumOfSell out]).

Is it something wrong with the formula or the Dlookup just works once!!!!

Many thanks

Demosthenis
Nov 6 '08 #1
Share this Question
Share on Google+
3 Replies


Expert Mod 2.5K+
P: 2,545
Hi, and Welcome to Bytes!

Firstly, your filter value in the DLookup tries to filter on a string literal value that is the name of the field you are comparing against - which can't possibly be right (..."[W]=" & "[Query5].[W]"). It is clearly incorrect that you are trying to lookup something in Query5 where its own field [W] equals itself - the filter will not filter anything in these circumstances.

Removing the redundant ampersand from your filter you really just have
"[W]=[Query5].[W]"

and since it is Query5 that you are looking up you really have a filter that is just

"[W]=[W]"

As this will always evaluate as True (just as 1=1 is True, as indeed anything = anything is also True) there is no filter at all being applied.

In any event, DLookup can only return one value - that is its job.

I reckon you have not thought through what you are trying to achieve here, and you will need to rethink your approach.

-Stewart
Nov 6 '08 #2

P: 5
Hi, and Welcome to Bytes!

Firstly, your filter value in the DLookup tries to filter on a string literal value that is the name of the field you are comparing against - which can't possibly be right (..."[W]=" & "[Query5].[W]"). It is clearly incorrect that you are trying to lookup something in Query5 where its own field [W] equals itself - the filter will not filter anything in these circumstances.

Removing the redundant ampersand from your filter you really just have
"[W]=[Query5].[W]"

and since it is Query5 that you are looking up you really have a filter that is just

"[W]=[W]"

As this will always evaluate as True (just as 1=1 is True, as indeed anything = anything is also True) there is no filter at all being applied.

In any event, DLookup can only return one value - that is its job.

I reckon you have not thought through what you are trying to achieve here, and you will need to rethink your approach.

-Stewart
Many thanks for your quick reply.

It is clear now where the problem is. Is it possible in some way to define the logic

"[Query4].[W]=[Query5].[W]"

since this is what I am trying to achieve. - the formula lies in Query 4.
Nov 7 '08 #3

Expert Mod 2.5K+
P: 2,545
Forget DLookup - it is not what you need. As I mentioned, it can only return a single value. You need to join Query 4 and Query 5 at least on the W field. You may also need to join on other key fields common to both queries that you don't mention, as otherwise the resultant query will cause multiplication of rows in the joined dataset.

Easiest way to do this is using the Access query editor, which will simplify the process of creating the joins, selecting the fields etc.

I strongly advise you to use meaningful names for fields, queries and so on. Names such as W, Query4, Query5 don't help you to understand what any of these are for. Using such meaningless names will hamper you in trying to see how to develop properly-joined queries.

-Stewart
Nov 7 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.