Hi James
I suggest you store two fields:
RecordDate (long)
RecordSequence (integer)
Store the date in the RecordDate field (I suggest datatype "long" instead of
"date/time" to ensure that it can only be a date part with no time) and
store the NNNN part in the RecordSequence field. Make the two fields
together the primary (or a unique secondary) composite key to ensure no
duplicates.
If you typically enter records on the date to which they apply, then set the
DefaultValue for RecordDate to "=Date()". Storing the date may have other
spin-offs, such as the ability to easily retrieve all records from a
particular month.
Now, the next sequence number for a given date may be ascertained as
follows:
iNextNum = Nz( DMax( "RecordSequence", "TableName", _
"RecordDate=" & Format( NewDateValue, "\#mm\dd\yyyy\#" ) ), 0) + 1
In plain English, find the maximum sequence number for the given date (and
if there ain't one, use zero) and then add one to it.
Now, the ID number you want in the form YYDDDNNNN can easily be generated on
the fly in a calculated field in a query, form or report:
IDString = Format( [RecordDate], "yy" ) _
& Format( DatePart ( "y", [RecordDate] ), "000" ) _
& Format ( [RecordSequence], "0000" )
This also means that if in the future you need to exceed the limit of 9999
records a day, all you need do is add another "0" to the format string and
the job is done.
--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand
JAMES FENNEL said:
I am responsible for keeping track of Safety discrepacies on board my ship.
I have a database to do so and I'm trying to automate some of the features to
make it easier. I would like to automate the ID feature using a Year-Julian
Date-auto increment format. Year in NN format, Julian Date in NNN format,
Auto Increment in NNNN format (not to exceed 9999 and reset each new julian
date). I would like this feature to key off when the the preceding field,
INSPTR loses focus. Can anybody out there help me?