john
let's say you need a record id for a record
an autonumber will do this. It doesn't matter if its negative.
- a one byte number ranges from 0 to 255 (256 values)
- a signed one byte number ranges from -128 to 127 (still 256 values)
an autonumber is 4 bytes, and therfore can hold 2^32 values, or approx 4billion. Because it is signed it can therefore be a value form -2billion to +2billion. That's all. The sign is immaterial. Itsa just 4-bytes ie 32 bits of 1s and 0s guarnateed to be unique. We just interpret it as a number. You can use this as a PK in a table, and as a FK in a linked table. Access can generate whatever number it wants. It is most likely to run in sequence, but it may not. If you scrap a record halfway through, you will lose the number it issued. It doesn't matter that it's negative - because no-one needs to ever see it. If you wnat something meaningful, then you need a different strategy. Note that many users, myself included will often have both an autonumber AND somethnig meaningful. The autonumber is there for efficient. The meaningful is there for your business.
BUT, let's say the number needs to have meaning, and say needs to be in sequence. Now one way is to execute a function to find the highest number in the table, and add one to it. That function is DMAX. Is there a problem with this. Yes, potentially. If you have several people inputting at the same time, they may all get issued with the same DMAX. (because your DMAX isn't recorded in the table until you save your record - so other users get the same DMAX)
So how do we get round this. By waiting till the very last moment to collect the DMAX. ie - wait until you actually commit the record save, and then instantly get the number. In theory, there are a few micro seconds when a clash could still happen - but in practice it wont happen. Note asso that DMAX can be "partitioned" if you will. You can find a DMAX foir items in May, and a DMAX for items in June. You don't just have to have one DMAX.
But this way, doesn't give you the number until right at the end, which may not be what you want. You may need to use the number at any earlier stage. So, instead - store the next number in a separate table. Now when you want a number, open the table, read the next number, increment it for the next user, and put it back. You don;t HAVE to do this, but if you LOCK the table first, this ensures there is absolutely NO possibility of a duplicate number. The downside here is that once you have your number - you may change your mind, and the number gets wasted, because you have already incremented the counter. Trying to fill the gaps is definitley best avoided.
so you can choose whichever scenario works for you.
----
Now if you do go for an ordinary number, rather than a autonumber, then you can easily enter old numbers, as long as they aren't duplicates - so backfilling numbers 1-400 isn't an issue.
Even with autonumbers, you can do the same - force numbers into the table via a query - but you can't edit them directly.
Having said that - You certainly can force numbers into Access tables, but I think at least some versions of SQL won't allow you to "force" in a particular number. But I am not 100% certain about that.