So i have a form where for every new entry of shipments you need to add a IDnumber to the shipment. The IDnumber is made of year and 4 digit increasing number. Here is the example: 15-0025 (the number 15 is the current year 2015, and the 0025 is the number that increases everytime, it starts from 0001).
Now I want it to check what last IDnumber of the shipment is and increase it or change it entirely if needed (I will explain this now).
Examples:
-I want it to increase the 4 digit number if the year from the previous IDnumber matches current year. So if last IDnumber was 15-0333, I want the next one to be 15-0334, increase by one.
-If the year has changed, example now is 2016. I want it to change the entire ID from example 15-2556 to 16-0001. Like a fresh start for a new year.
I have done some code for this but some things I just didn't know how to do.
First: I dont know how to get from the last IDnumber the year part of the IDnumber (those first two numbers) to compare it with the current year.
Second: It works when I put example 14-2545 for the last IDnumber and it changes it to 15-0001. But it does not increase the number when i need it to be 15-0002 etc.
The code is activated when they click on the textbox. If anyone can help I would be gratefull.
Now I want it to check what last IDnumber of the shipment is and increase it or change it entirely if needed (I will explain this now).
Examples:
-I want it to increase the 4 digit number if the year from the previous IDnumber matches current year. So if last IDnumber was 15-0333, I want the next one to be 15-0334, increase by one.
-If the year has changed, example now is 2016. I want it to change the entire ID from example 15-2556 to 16-0001. Like a fresh start for a new year.
I have done some code for this but some things I just didn't know how to do.
First: I dont know how to get from the last IDnumber the year part of the IDnumber (those first two numbers) to compare it with the current year.
Second: It works when I put example 14-2545 for the last IDnumber and it changes it to 15-0001. But it does not increase the number when i need it to be 15-0002 etc.
The code is activated when they click on the textbox. If anyone can help I would be gratefull.
Code:
Private Sub IDnumber_Click()
Dim CurrentYear As String
Dim YearofILastIDnumb As String
YearofILastIDnumb = ????????
CurrentYear= Format(Now(), "yy")
If YearofILastIDnumb = Null Then
Me.IDnumber.Text = CurrentYear & "-0001"
End If
If CurrentYear > YearofILastIDnumb Then
Me.IDnumber.Text = CurrentYear & "-0001"
End If
If CurrentYear = YearofILastIDnumb Then
If Forms!frmNewContract!subLastIDnumber!LastIDnumber = CurrentYear & "-0001" Then
Me.IDnumber.Text = Forms!frmNewContract!subLastIDnumber!LastIDnumber + 1
Else
Me.IDnumber.Text = Forms!frmNewContract!subLastIDnumber!LastIDnumber + 1
End If
End If
End Sub