John's code below should work for assigning the sequence number in your
present scheme. A better design would be to split the sequence number and
the year into two fields. Data fields should be atomic, without any
meaning to sub-sections of the field. So a long integer year field, with a
meaningful name like orderYear or meetingYear or whatever it is (since
'year' is a reserved word and should not be used as a field name) and a
second long integer for annualSequenceNumber. That avoids the issue John
mentioned of being limited to 99 rows per year and programming against the
data is clearer because the data is simpler. You can use an expression (in
a query, form or report) to display your current ID:
OriginalID = Format([annualSequenceNumber], "00") & "/" & [orderYear]
To get the next data values, you could use code like this:
Dim thisYear as Long
Dim seqNumNext as Long
Dim strWhere as string
thisYear = Year(Date())
strWhere = "[orderYear]=" & thisYear
seqNumNext = 1 + nz(dMax("[annualSequenceNumber]", "[tablename]",
strWhere), 0)
In the table design mode you could set the default value for orderYear to
be Year(Date()), so that would automatically be entered with the correct
value. I don't think you can use the expression for seqNumNext as a
default value, but you could try a variation like this and see if it
works:
1 + nz(dMax("[annualSequenceNumber]", "[tablename]", "[orderYear]=" &
Year(Date())), 0)
Jon said:
Hi,
01 & 02 are not a date, they are a sequence number? Please advice???