J
Jan Il
Hi all Windows XP Pro SP2 - Access 2003
I need to be able to have a sequential numbering system for a text box on a
data entry form, to be able to get the InvoiceNo. control to automatically
list the next number in line when the form is opened, or, when a record is
saved and a new record is ready to be entered. The new number should based
upon the last number saved or listed in the table, that way each time a
number is saved a new number will automatically be displayed in the
InvoiceNo. box, ready for the next entry.
The Control name for the Invoice number is txtInvoiceNo, which is bound to
the InvoiceNo field on the tblSalesRecord
I have tested with the following code, but, I don't think it is quite right,
particularly here:
"InvoiceNo Like 'Invoice*'")
Plus...I am not sure in which Event this should be placed, Before or After
Update.
***********************Start Code**********************
Private Function NextInvoiceNo() As String
Dim strMaxNum As String
strMaxNum = vbNullString & _
DMax("InvoiceNo, tblSalesRecord", _
"InvoiceNo Like 'Invoice*'")
If Len(strMaxNum) = 0 Then
NextInvoiceNo = "000001"
Else
NextInvoiceNo = _
"InvoiceNo" & Format(1 + CLng(Mid(strMaxNum, 7)), "000000")
End If
End Function
*************End Code***************************
I would truly appreciate some suggestions on this process
Jan
I need to be able to have a sequential numbering system for a text box on a
data entry form, to be able to get the InvoiceNo. control to automatically
list the next number in line when the form is opened, or, when a record is
saved and a new record is ready to be entered. The new number should based
upon the last number saved or listed in the table, that way each time a
number is saved a new number will automatically be displayed in the
InvoiceNo. box, ready for the next entry.
The Control name for the Invoice number is txtInvoiceNo, which is bound to
the InvoiceNo field on the tblSalesRecord
I have tested with the following code, but, I don't think it is quite right,
particularly here:
"InvoiceNo Like 'Invoice*'")
Plus...I am not sure in which Event this should be placed, Before or After
Update.
***********************Start Code**********************
Private Function NextInvoiceNo() As String
Dim strMaxNum As String
strMaxNum = vbNullString & _
DMax("InvoiceNo, tblSalesRecord", _
"InvoiceNo Like 'Invoice*'")
If Len(strMaxNum) = 0 Then
NextInvoiceNo = "000001"
Else
NextInvoiceNo = _
"InvoiceNo" & Format(1 + CLng(Mid(strMaxNum, 7)), "000000")
End If
End Function
*************End Code***************************
I would truly appreciate some suggestions on this process
Jan