koolwaters
Active Member
- Joined
- May 16, 2007
- Messages
- 403
Happy New Year Everyone!
We have a database we are using for invoicing and we want the invoice number to be the current year and an incremented number, but we want the incremented number to restart at 1 for each year (2015-01, 2015-02, 2015-03, 2015-04, 2016-01, 2016-02, etc.).
The code below worked fine for 2015 but I need some help in adjusting it for 2016. The last invoice number for 2016 is 781 so the current code returns 2016-0782 as the invoice number but we want it to be 2016-01 and then increment from there (2016-01, 2016-02, 2016-03, etc.).
Any suggestions?
Thanks in advance!
We have a database we are using for invoicing and we want the invoice number to be the current year and an incremented number, but we want the incremented number to restart at 1 for each year (2015-01, 2015-02, 2015-03, 2015-04, 2016-01, 2016-02, etc.).
The code below worked fine for 2015 but I need some help in adjusting it for 2016. The last invoice number for 2016 is 781 so the current code returns 2016-0782 as the invoice number but we want it to be 2016-01 and then increment from there (2016-01, 2016-02, 2016-03, etc.).
Any suggestions?
Code:
Dim strNextInvoiceNo As Integer
Dim strInvoiceNo As String
strForm = "frmInvoice"
strNextInvoiceNo = Nz(DMax("[LastInvoiceNo]", "tblInvoice"), 0) + 1
strInvoiceNo = DatePart("yyyy", Now()) & "-" & "0" & strNextInvoiceNo
DoCmd.OpenForm stDocName, acNormal, , , acFormAdd
Forms.frmInvoice.InvoiceNo = strInvoiceNo
Forms.frmInvoice.LastInvoiceNo = strNextInvoiceNo
Thanks in advance!