I have a database which contains a table with an autonumber ID, set as indexed (no duplicates). After adding and deleting a few data, I found that the autonumber has gone out of sync. For example, my sample database has 1302 records, and the next new number should have an ID of 1302. But it didn’t. It started with a new record with ID 787, which was already used by another recordd! Of course it was an error and my attempted new record wasn’t accepted. Then I exited and started again. This time the new record had an ID 788, which was again used and again caused an error.
To overcome the problem, I copied the problem table to another name, delete the old one and rename the new one back to the old table name. Then the automatic ID works as expected. A new record will start with a number immediately after the last one. The table works fine after this (so far!).
My question is – how does the autonumber go out of sync and what causes it? Is there a way or ways the program can detect / prevent the autonumber from going out of sync?