I assume that the first four digits are supposed to change to 2007 next
year, and the numbering sequence to start over at 001. This code is another
approach.
In the form's Current event:
If Me.NewRecord Then
Dim strWhere, strDate As String
Dim varResult As Variant
strDate = Format(Date, "yyyy")
strWhere = "DateCode Like """ & strDate & "*"""
varResult = DMax("DateCode", "tblYourTable", strWhere)
If IsNull(varResult) Then
Me.txtDateCode = strDate & "-001"
Else
Me.txtDateCode = Left(varResult, 5) &
Format(Val(Right(varResult, 3)) + 1, "000")
End If
End If
DateCode is the table field containing 2006-001, 2006-002, etc. txtDateCode
is the text box bound to that field.
Note that DateCode is the PK (or otherwise does not allow duplicates),
assigning the number in the form's Current event could create conflicts in a
multi-user environment if another user starts a record at about the same
time. There are ways of handling this, but I will wait to hear if it is a
multi-user environment.