An autonumber field is fine as the primary key field of a table - it is
merely a unique number that can serve as a single field primary key. As long
as you and your users attach no other importance to it, it is fine.
Unfortunately, many times we need a numeric field like an autonumber which
needs to be a bit more controlled (checknumbers, invoice numbers etc.) -
this is when we recommend creating your own counter field. Often, there is
no real business need for controlling the number but the users get so
attached to the concept of sequenced identifiers that they insist on having
"meaningful" numbers.
The easiest way to create a custom counter is using the Dmax function where
you grab the highest existing value from the table and then increment it.
This method is fine in some environments but not in a multiuser situation
where 2 or more people are simultaneously entering records into the same
table.
For example: You have a table tblCustomer and you want to increment Custid
without using an Autonum field. The following will get the current max value
of Custid, increment it by 1 and then put the new value into the control
me.custid:
me.custid=nz(dmax("Custid","tblCustomer"),0)+1
Another method that works well for the multiuser situation is create a table
which has only one row. This table holds the next available number for the
counter. Build a function, GetInvoiceNum (or whatever you want to call it).
This function will open the table with the dbDenyRead option, which prevents
other users from opening the table until this instance of the function
closes it. The function gets the next value (the return value of the
function) and the increments it and updates the table. In the error handling
of the function, if the table can't be opened because it is locked, your
function should wait and then try again.
For more info on one method for this see:
ACC2000: How to Create a Multiuser Custom Counter ID: Q210194
http://support.microsoft.com/default.aspx?scid=kb;[LN];210194
Another resource is the Access 20XX Developers Handbook (Volume 2), Litwin,
Getz and Gilbert which has some code for this which you can probably use as
is in your project.