DMax Problem

D

DS

My DMax statement is not working. It only works when I have records.
If i start fresh it refuses to give me a starting number of 1 let alone
any number, is the syntax wrong?

Forms!Sales.SalesDetails!LineID = DMax("[LineID]", "SalesDetails") + 1

Thanks
DS
 
D

Dirk Goldgar

DS said:
My DMax statement is not working. It only works when I have records.
If i start fresh it refuses to give me a starting number of 1 let
alone any number, is the syntax wrong?

Forms!Sales.SalesDetails!LineID = DMax("[LineID]", "SalesDetails") + 1

Thanks
DS

If there aren't currently any records, then the maximum value from them
is going to be Null -- unknown or meaningless. Use the Nz() function to
convert that Null to zero:

Forms!Sales.SalesDetails!LineID = _
Nz(DMax("[LineID]", "SalesDetails"), 0) + 1
 
V

Van T. Dinh

DMax returns Null if you start fresh.

Try:

Forms!Sales.SalesDetails!LineID = Nz(DMax("[LineID]", "SalesDetails"), 0) +
1
 
D

DS

Dirk said:
My DMax statement is not working. It only works when I have records.
If i start fresh it refuses to give me a starting number of 1 let
alone any number, is the syntax wrong?

Forms!Sales.SalesDetails!LineID = DMax("[LineID]", "SalesDetails") + 1

Thanks
DS


If there aren't currently any records, then the maximum value from them
is going to be Null -- unknown or meaningless. Use the Nz() function to
convert that Null to zero:

Forms!Sales.SalesDetails!LineID = _
Nz(DMax("[LineID]", "SalesDetails"), 0) + 1
Thanks everyone. It worked like a charm!
DS
 

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