I have an AutoNumber field in my database but Access skipped some numbers;
how do I fix this? I want all the numbers to increment by "1"...instead, it
goes from 1-43 and 154-208. I tried to change the starting number of an
AutoNumber field but it didn't work for this particular case.
Any help would be appreciated.
This is in the nature of autonumbers. An Autonumber has one purpose,
and one purpose ONLY: to provide a unique key. It is not designed or
implemented to be sequential, continuous, or gap-free. Deleting a
record will leave a gap; hitting <Esc> after starting to enter a
record will leave a gap; running an Append query (as you may have
done) will leave a gap, sometimes a very large one.
If the values of the numbers are intended for human consumption and
gaps are unwanted, *don't use Autonumber*. Instead use a Long Integer
field and VBA code in the Form that you use to update the table to
increment the number. If the ID is the only required field you can use
code like this in the form's BeforeInsert event:
Private Sub Form_BeforeInsert(Cancel as Integer)
Me!txtID = NZ(DMax("[ID]", "[tablename]")) + 1
Me.Dirty = False ' write the new record to disk immediately
' to prevent another user from getting the same number
End Sub
John W. Vinson[MVP]