DMax

J

Johnkl

Hi all

I have a small problem with Dmax

I want to increment the Invoice Number depending on the invoice Series to the
next number as follows :
Invoice Series A , Invoice Number 1.
Invoice Series No Series , Invoice Number 1

Now when I issue the next invoice eith Invoice Series A the Invoice Number is
To be 2 and so on. For this purpose I use the following code after the Before
Insert Event of A Form


Private Sub Form_BeforeInsert(Cancel As Integer)

Me.InvoiceNo = Nz(DMax("[Invoice]", "[tblInvoices]", "InvoiceSeries = '" & Me.
InvoiceSeries & "'")) + 1
End Sub

The problem I face is that it always returns 1.

Can anyone please help!!!!
Kind regards
John
 
S

Stefan Hoffmann

hi John,
Private Sub Form_BeforeInsert(Cancel As Integer)

Me.InvoiceNo = Nz(DMax("[Invoice]", "[tblInvoices]", "InvoiceSeries = '" & Me.
InvoiceSeries & "'")) + 1
End Sub

The problem I face is that it always returns 1.
Wrong event? Try Form_AfterInsert. And use Nz(DMax(), 0).


mfG
--> stefan <--
 
G

Guest

I think the Before Insert may be too late. Also, there is an error in your
statement.
It should be
Me.InvoiceNo = Nz(DMax("[Invoice]", "[tblInvoices]", "InvoiceSeries = '" & Me.
InvoiceSeries & "'"), 0) + 1

I think a better place would be to put it in the After Update event of the
Invoice Series control.
 

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