IS this DLOOKUP possible within a query?

S

Stu

I want to create the lookup criteria from a date field withn the query
itself but can't get it to work. The lookup I'm using always returns
1 (when it should be 908,1008 etc)

DLookUp("WkInd","tblWeekNum",(Format([AK_DELIV_DATE],"wwyy")))

Is it possible to do the lookup this way and, if so, can you please
tell me where Im going wrong.

TIA
 
A

Allen Browne

The 3rd argument for DLookup() is the criteria.
You need to use an expression such as:
SomeField = SomeValue
e.g.:
"[Field99] = 999"

As it is, the expression:
(Format([AK_DELIV_DATE],"wwyy"))
will evalutate to something like:
2608
That text can be treated as a non-zero value, so Access treats the criterion
as True. (Zero is False.) Since it is True for any record, the first record
it tries matches, and hence you get the first one returned.

For help with forming the 3rd argument, see:
Getting a value from a table: DLookup()
at:
http://allenbrowne.com/casu-07.html
 
S

Stu

The 3rd argument for DLookup() is the criteria.
You need to use an expression such as:
    SomeField = SomeValue
e.g.:
    "[Field99] = 999"

As it is, the expression:
    (Format([AK_DELIV_DATE],"wwyy"))
will evalutate to something like:
    2608
That text can be treated as a non-zero value, so Access treats the criterion
as True. (Zero is False.) Since it is True for any record, the first record
it tries matches, and hence you get the first one returned.

For help with forming the 3rd argument, see:
    Getting a value from a table: DLookup()
at:
   http://allenbrowne.com/casu-07.html

--
Allen Browne - Microsoft MVP.  Perth, Western Australia
Tips for Access users -http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.




I want to create the lookup criteria from a date field withn the query
itself but can't get it to work.  The lookup I'm using always returns
1 (when it should be 908,1008 etc)
DLookUp("WkInd","tblWeekNum",(Format([AK_DELIV_DATE],"wwyy")))

Is it possible to do the lookup this way and, if so, can you please
tell me where Im going wrong.
TIA- Hide quoted text -

- Show quoted text -

Sorry, me being stupid :)

This is what I should be using and still can't get it to work.

DLookUp("WkInd","tblWeekNum","WkYr" =
(Format([AK_DELIV_DATE],"wwyy")))
 
A

Allen Browne

Put the = inside the quotes, and concatenate with &.

Look at the link in the previous reply if you are still stuck.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Sorry, me being stupid :)

This is what I should be using and still can't get it to work.

DLookUp("WkInd","tblWeekNum","WkYr" =
(Format([AK_DELIV_DATE],"wwyy")))
 
S

Stu

Put the = inside the quotes, and concatenate with &.

Look at the link in the previous reply if you are still stuck.

--
Allen Browne - Microsoft MVP.  Perth, Western Australia
Tips for Access users -http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


Sorry, me being stupid :)

This is what I should be using and  still can't get it to work.

DLookUp("WkInd","tblWeekNum","WkYr" =
(Format([AK_DELIV_DATE],"wwyy")))

Thanks Allen - got it now.
 

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