Problem with DMAX

rnutts

Registered User.
Local time
Today, 18:32
Joined
Jun 26, 2007
Messages
110
I have the following code in the on click event of a commad button
I am looking to duplicate the majority of the last record using this command button(further similar lines of code not shown). The problem I am encountering is that the Field SalesID is an autonumber field and is at 23650 as a record count and the record this bit of code returns is record 110. Can someone tell me where I am going wrong with the criteria
I have tried taking out the Nz portion and also used DLast, but to no effect.

Me.ProjectID = DLookup("[ProjectID]", "tblSalesDetails", Nz(DMax("[SalesID]", "tblSalesDetails"), 0))

Many thanks in advance

Richard
 
What is the relation between the code you show and your question? Your question is about some "record", your code returns a field value for the record with largest SalesID. Or perhaps not, since there is no condition specified as such. See Dlookup in the documentation.
 
I am looking for the code to return the field value for the record with the largest SALESID, however what it is returning is the field value for the record with a SALESID of 110, when it should be the record with a SALESID value of 23651

Thanks

Richard
 
what do you get from this? do you get the MAX SalesID?
DMax("[SalesID]", "tblSalesDetails")
 
Finally cracked it with
Me.ProjectID = DLookup("[ProjectID]", "tblSalesDetails", "SalesID = " & DMax("[SalesID]", "tblSalesDetails"))

Thanks for the help and pointing me to the fact the criteria didnt have a condition.

Richard
 

Users who are viewing this thread

Back
Top Bottom