Error unless there is a number listed

B

Bob Vance

I am getting an error with this part of my code:
lngInvoiceID = DMax("InvoiceID", "tblInvoice") + 1
But only if it is my first Invoice can I add a null factor in!
 
J

Jeanette Cunningham

Hi Bob,
one way is to first test for any existing invoice number.

If DCount("*", "tblInvoice") >0 Then
lngInvoiceID = DMax("InvoiceID", "tblInvoice") + 1
Else
lngInvoiceID = 1
End If


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
K

Ken Snell \(MVP\)

lngInvoiceID = Nz(DMax("InvoiceID", "tblInvoice"), 1) + 1

The above code step will use the number 1 when it's the first invoice
number.
 
Top