-----Original Message-----
Thanks so much for the recommendations on my problem. I
used your code at the bottom and got it to work. I was
wondering if the code you provided will also reset the
autonumber sequence (i.e. your "FileSeq") to zero once the
year automatically changes. In other words, when 2005
comes...will the sequence reset to look like 2005-0001?
Yes, it will: let me explain why.
Private Sub Form_BeforeInsert(Cancel as Integer)
Me!txtFileSeq = NZ(DMax("[FileSeq]", "[your-table-name]", _
"[FileYear]= " & Me!FileYear)) + 1
End Sub
The DMax() function takes three arguments: a field to be looked up; a
"domain" - a table or query in which to look; and a criterion as the
third argument.
The criterion will search for all records in your-table- name for which
the table's FileYear field is equal to the FileYear control on the
form. If it's 2005, that control will (presumably) contain 2005, so it
will find all the 2005 records, if any. If there are already some
records in 2005, the DMax() function will return the largest value of
FileSeq in that group; if there aren't any at all, it will return
NULL.
The NZ() function will either return the maximum existing FileSeq
value, or 0 if DMax() didn't return anything - that's what NZ does,
converts Null to Zero.
Finally the expression (as I've corrected it here... as written it
would NOT work!!!) will add 1 to whatever was returned by NZ; if there
were no 2005 records you'll get 0 + 1 and txtFileSeq will be set to 1,
otherwise it will add one to the largest existing value and use that.
.