What I want to do is create an incrementing id that resets to 1 every year with a prefix. The prefix is "10yy/", where 10 refers to the table and "yy" is the current year. For 2015 I want it to go:
1015/0001
1015/0002
etc.
In 2016 I want it to go:
1016/0001
1016/0002
etc.
The table is "RoadIM" and the id field is "RIMID"
My code is:
Every valid expression I have put after the LIKE has resulted in every new record taking the 1015/0001 id.
What I want to put after the LIKE is something that means "10yy/*", where "yy" is the current year, so that it checks the last entry from the current year.
I would really appreciate any help, because this has caused me hours of frustration, since I'm new to basic.
Thank you!
1015/0001
1015/0002
etc.
In 2016 I want it to go:
1016/0001
1016/0002
etc.
The table is "RoadIM" and the id field is "RIMID"
My code is:
Code:
[B]Private Sub Form_BeforeInsert(Cancel As Integer)
Dim vLast As Variant
Dim iNext As Integer
vLast = DMax("[RIMID]", "[RoadIM]", "[RIMID] LIKE "[COLOR="Red"][SIZE="6"]I don't know[/SIZE][/COLOR]")
If IsNull(vLast) Then
iNext = 1
Else
iNext = Val(Mid(vLast, 4)) + 1
End If
Me![RIMID] = "10" & Format(Date, "yy") & "/" & Format(iNext, "0000")
End Sub
[/B]
Every valid expression I have put after the LIKE has resulted in every new record taking the 1015/0001 id.
What I want to put after the LIKE is something that means "10yy/*", where "yy" is the current year, so that it checks the last entry from the current year.
I would really appreciate any help, because this has caused me hours of frustration, since I'm new to basic.
Thank you!
Last edited: