I need to generate unique invoice numbers for my Access (2010) database. The numbers should be in the format year+sequential number, e.g. 20101447 for the 1447th invoice of 2010. I looked around for a while, but a lot of the Google results suggest using an autonumber and I’m quite certain that’s not a very solid way of doing it. (because autonumbers are only guaranteed to be unique, nothing else)
The database isn’t going to be used by multiple users at once for now, but I don’t feel like going with a totally hacked together solution either.
EDIT
I also found this website that discusses sequential numbering using the DMax function. Scenario #2 is exactly what I had in mind, and I think it’s good enough for my use case. I’ll make sure the user is notified in the rare (for me) event that the database got changed before completely entering and saving a new invoice.
EDIT2
FYI: The numbering scheme isn’t a fiscal requirement, but just our custom numbering. I didn’t want to change without a good reason to.
If you have the ability to change the database schema:
year field.
these values appropriately.
the current year and then query the
database for the maximum sequential
number where year = current year.
If you can’t change the database schema:
invoice number starts with current
year
EDIT
If you can add another table, have a table that stores the ‘max’ sequential number for each year. Every insert will lock the table, get the value and then increment it. Think of it as your invoice number generator table.