Question : Dlookup(price of item the last date/time it was completed)

Hello,

The very simple method is to look up the highest number for the item then use that to look up the price:

DLookup("[Price]","Calculation","[AutoNumber]=" & DMax("[AutoNumber]","Calculation","[ItemNumber] = '" & YourItemNumber & "'") & "")

and it works great but now I want to exchange column "AutoNumber" with "Date" and my criteria should look like this:

DLookup("[Price]","Calculation","[Date]=" & DMax("[Date]","Calculation","[ItemNumber] = '" & YourItemNumber & "'") & "")

but I recive syntax error messages(I assume because column "Date" must be marked with sign "#")

Any help is appreciated.

Thanks
Adnan

Answer : Dlookup(price of item the last date/time it was completed)

Firstly, you should never have a fieldname the same as an Access reserved word - date.  Try changing the field name to something like fldDate.  I have just spent the last four hours chasing this one and I was able to get it to work by changing regional settings to shortdate yyyy-mm-dd.  With dd/mm/yyyy I kept getting an "Illegal use of null" error message.

This line of code in the immediate pane worked with table Table1, and fields DDate and ColA.  I set YourNo to 2, valid for my test case and it produced the correct date.

YourNo = 2
? DLookup("ColA","Table1","DDate=#" & DMax("DDate","Table1","ID=" & YourNo) & "#")
2004-06-01

dan vella:  Were you able to get your solution to work with test data?
Random Solutions  
 
programming4us programming4us