Tim said:
My database contains a specific record number XXXX-YYY.
XXXX = Year
YYY = Record Number (starting with 001)
How would I go about formatting the field to output that format
automatically? In addition, what do I need to do to reset YYY to 001
when the next year?
The easiest, most efficient, and most flexible way to do this is to have two
fields [RecordDate] and [ID]. RecordDate is a DateTime with a default value of
Now() so it is easy to set up and no code is required to populate it. There are
numerous situations where knowing exactly when a record was created is
beneficial so this provides that at the same time.
Once you have a [RecordDate] then assignment of the other field [ID] is very
simple. As each record is inserted you just need to find the highest ID value
that was created in the current year and add 1 to it. The BeforeUpdate event it
best for this...
If Me.NewRecord Then
Me![ID] = Nz(DMax("ID", "TableName", "Year(RecordDate) = Year(Date())"), 0)
+ 1
End If
On your forms and reports you can display these two fields as one identifier
with an expression of...
=Format([RecordDate], "YYYY\-") & Format([ID], "000")
....that will give you the format you asked for.