I have a table with a field with projectsnumbers in it. Now I need to
created records for the next year and the projectsnumbers must be automatic
generated by counting +1
I want to use a query but how can I do so?
I dont want to use the autonumber option because f.e. my last number was
2589 and my next number must be 2590 and so on.
Kees
If I understand aright, you would like a project number that works
sort of like an autonumber, but that starts over at the new year...
right?
One way to do this is to use a Form to enter the data (table
datasheets don't have usable events and should not be used routinely
in any case!). In the Form's BeforeInsert event put code like
Private Sub Form_BeforeInsert(Cancel as Integer)
Me!txtProjectNumber = NZ(DMax("[ProjectNumber]", "[Projects]", _
"[ProjectYear] = Year(Date())")) + 1
Me.Dirty = False
End Sub
This will look up the largest existing project number for the current
year (guessing that you have a ProjectYear field); if it's the very
first project for a year this will be NULL, and the NZ function will
return 0. It then adds 1 to this number and stores it in the form
control txtProjectNumber (which should of course be bound to the
ProjectNumber field).
The Me.Dirty = False immediately writes the record to disk so that
another user won't grab the same project number while you're working
on the rest of the fields in the record.
John W. Vinson[MVP]