I read through this thread and implemented a few features that were suggested by Pat.
However, I'm still having trouble grasping how I can get the incrementing number to reset at the start of a new year. I would prefer for it to continue on each year, but my boss likes it to reset.
What I need is the year, and then an incrementing number after that. Example:
2006-0001
2006-0002
2006-0003
2007-0001
2007-0002
2007-0003
I have three fields in my table. One to store the year; one to store the incrementing number; and the last to store the combined year and number. I want to check the year and then increment the number +1 for the incrementing number for that year. If it is a new year, the numbering will start at 1.
My code is as follows:
Private Sub Form_BeforeInsert(Cancel As Integer)
Dim nextNum As String, myYear As String
myYear = Format(Year(Date))
If Me.NewRecord Then
On Error Resume Next
'incrementing number
nextNum = Nz(DMax("[txtIncrement]", "[tblTest]", [txtYear] = myYear), 0) + 1
Me.txtIncrement = nextNum
'combining the results and storing it in output
Me.txtOutput = myYear & "-" & Format(nextNum, "0000")
End If
End Sub
I'm still fairly new to vba so any help would be tremendous. If I missed a thread that has better step-by-step information, then please let me know. This forum has been great.
However, I'm still having trouble grasping how I can get the incrementing number to reset at the start of a new year. I would prefer for it to continue on each year, but my boss likes it to reset.
What I need is the year, and then an incrementing number after that. Example:
2006-0001
2006-0002
2006-0003
2007-0001
2007-0002
2007-0003
I have three fields in my table. One to store the year; one to store the incrementing number; and the last to store the combined year and number. I want to check the year and then increment the number +1 for the incrementing number for that year. If it is a new year, the numbering will start at 1.
My code is as follows:
Private Sub Form_BeforeInsert(Cancel As Integer)
Dim nextNum As String, myYear As String
myYear = Format(Year(Date))
If Me.NewRecord Then
On Error Resume Next
'incrementing number
nextNum = Nz(DMax("[txtIncrement]", "[tblTest]", [txtYear] = myYear), 0) + 1
Me.txtIncrement = nextNum
'combining the results and storing it in output
Me.txtOutput = myYear & "-" & Format(nextNum, "0000")
End If
End Sub
I'm still fairly new to vba so any help would be tremendous. If I missed a thread that has better step-by-step information, then please let me know. This forum has been great.