Invoice number

  • Thread starter Thread starter Sparky
  • Start date Start date
S

Sparky

I want to automatically enter an invoice number into an invoiceref
field when I enter the invoice date into invoicedate field. My problem
is how do I take the previous invoice number and increment by 1?

Thanks.
 
Use the BeforeUpdate event procedure of your form to lookup the maximum
number used so far in the table, and add one.

This event is the last possible moment before the record is saved. Leaving
it to the last moment reduces the chance that 2 users will be given the same
number.

Example, assuming a field named InvoiceNum, in a table named Table1:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.[InvoiceNum]) Then
Me.[InvoiceNum] = Nz(DMax("InvoiceNum", "Table1"),0) + 1
End If
End Sub
 
Sparky,

Nz(DMax("YourInvoiceNumField","YourInvoicesTable"),0) + 1

Also, you might consider using it instead in the form's BeforeUpdate event
procedure, especially if you are in a multi-user environment.

Brian
 
Sorry Allen,

Your post didn't show up in my reader until after I sent my own post.

Brian


Allen Browne said:
Use the BeforeUpdate event procedure of your form to lookup the maximum
number used so far in the table, and add one.

This event is the last possible moment before the record is saved. Leaving
it to the last moment reduces the chance that 2 users will be given the same
number.

Example, assuming a field named InvoiceNum, in a table named Table1:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.[InvoiceNum]) Then
Me.[InvoiceNum] = Nz(DMax("InvoiceNum", "Table1"),0) + 1
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Sparky said:
I want to automatically enter an invoice number into an invoiceref
field when I enter the invoice date into invoicedate field. My problem
is how do I take the previous invoice number and increment by 1?

Thanks.
 
Thanks to all. Works a treat!




Sparky,

Nz(DMax("YourInvoiceNumField","YourInvoicesTable"),0) + 1

Also, you might consider using it instead in the form's BeforeUpdate event
procedure, especially if you are in a multi-user environment.

Brian
 

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

Back
Top