You can do this in a form, not at table level. In the BeforeInsert event
procedure of a form bound to the table put the following code:
Dim strCriteria As String
Dim intCurrentYear As Integer
Dim varLastNumber As Variant
intCurrentYear = Year(VBA.Date)
strCriteria = "Left(ID,4) = """ & intCurrentYear & """"
varLastNumber = DMax("ID", "YourTableName", strCriteria)
If IsNull(varLastNumber) Then
Me.ID = intCurrentYear & "001"
Else
Me.ID = varLastNumber + 1
End If
This will work fine in a single user environment, but in a multi-user
environment on a network conflicts could arise if two or more users are
adding a new record simultaneously. What would happen is that the first user
to save the record could do so successfully, but the other user(s) would
experience an error by virtue of the primary key violation. Roger Carlson
has a solution to this at:
http://www.rogersaccesslibrary.com/...?TID=395&SID=83z7c11zc7b721d2a1e51989c53d7ffb
Ken Sheridan
Stafford, England