I am trying to generate an invoice number using the following code. It gets the number just fine, but I want to check the number generated against the table to make sure there are no duplicates, and if there is I want the number to increase by 1.
Private Function NextNumber() As String
Dim numRecs As Long
Dim Serial As String
Dim Report As String
Dim Sequential As String
Dim HowMany As Long
numRecs = DCount("*", "customers")
HowMany = numRecs + 1
Sequential = Left$(String(3, "0"), 4 - Len(Str(HowMany))) & Right$(Str(HowMany), Len(Str(HowMany)) - 1)
Report = DatePart("yyyy", Date)
Serial = Report & "1" & Sequential
NextNumber = Serial
End Function
____________________________
Private Sub btnInvoiceNo_Click()
Me.InvoiceNo = NextNumber
End Sub
_____________________
I would like the number to get checked when I click on the button for the invoice number, but I'm stumped (long day already). Any suggestions?
Private Function NextNumber() As String
Dim numRecs As Long
Dim Serial As String
Dim Report As String
Dim Sequential As String
Dim HowMany As Long
numRecs = DCount("*", "customers")
HowMany = numRecs + 1
Sequential = Left$(String(3, "0"), 4 - Len(Str(HowMany))) & Right$(Str(HowMany), Len(Str(HowMany)) - 1)
Report = DatePart("yyyy", Date)
Serial = Report & "1" & Sequential
NextNumber = Serial
End Function
____________________________
Private Sub btnInvoiceNo_Click()
Me.InvoiceNo = NextNumber
End Sub
_____________________
I would like the number to get checked when I click on the button for the invoice number, but I'm stumped (long day already). Any suggestions?