Hi
I have a dlookup statement inside a query and I am not getting the result i
need, I think I need to put in # symbols but can't figure out the correct
syntax, any help would be appricated
FISCYR: DLookUp("YR","tblFiscalPeriod","Operations.Date" Between "Startdate"
And "EndDate")
Thanks
First off, don't use the fieldname Date if you can avoid it. It's a
reserved word (for the builtin Date() function which returns the
system clock date). If you must use it, always enclose it in square
brackets. Even worse, fieldnames should *never* contain periods, since
a period is the delimiter between tablenames and fieldnames in
queries; Operations.Date means "the field named Date in the table
named Operations". Square brackets *might* avoid problems but renaming
the field (say to Operations_Date) would be much better!
Thirdly, why use a DLookUp inside a query, rather than just using
criteria in the query?
Those concerns aside: you need to have the third parameter end up as a
text string which is a valid SQL WHERE clause, without the word Where.
Guessing that tblFiscalPeriod has fields named StartDate and EndDate,
and you want to return records where the field [Date] in the outer
query (based on the table Operations I presume), you should be able to
use
DLookUp("YR", "tblFiscalPeriod", "[StartDate] <= #" & [Date] & "# AND
[EndDate] >= #" & [Date] & "#")
You may be able to avoid the tblFiscalPeriod altogether if your fiscal
year begins in (say) July - DatePart("yyyy", DateAdd("m", 7, [Date]))
will return 2004 for July 1 2003 through June 30 2004 and so on.
John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps