INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

General Information

Use of Autonumber by mph1
Posted: 5 May 04

(Q)     In a table I'm using an Autonumber Field as the primary ID.   But if the user creates a new record and closes the form without saving it,   the Autonumber field still increases by one. This creates gaps in the continuity of the primary key field. How can I:

(a)  stop the Autonumber incrementing itself if the record wasn't created; and
(b)  force a renumber of this field to occupy contiguous numbers if I was delete record(s) from the table?

(A)   There is no such thing as a record number in Access.

Records just "are" - a table is a big, unsequenced bucket. Indexes and queries provide order to the records in the bucket.

Autonumber is simply a way to create a unique identifier for each record. It should NEVER be treated as a meaningful piece of data.

If you need a meaningful sequencer (like to assign user numbers), you have to create it and manipulate it yourself. You will need to stop using Autonumber, and create a sequence number that you increment yourself and apply to the record when it is saved.

You can also capture the numbers from deleted records and re-use  them. If, however, you have the possibility of related records using the number as a foreign key - do not reuse old numbers.

Now, for your db to "work" primary keys do not need to be continuous numbers; they just need to be unique - which is why the Autonumber function works like it does.

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

This was NOT written by myself. The credit goes to Keri Hardwick.

Back to Microsoft: Access Forms FAQ Index
Back to Microsoft: Access Forms Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close