Print Page | Close Window

reset autonumber for new records

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Database Discussion
Forum Description: Discussion and chat on database related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=4275
Printed Date: 29 March 2026 at 7:49pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: reset autonumber for new records
Posted By: Routhg
Subject: reset autonumber for new records
Date Posted: 15 July 2003 at 9:08pm

Hi,

Using Access2000 I have an ID field, an autonumber field, that for some unknown reason went from around 3,000 to 453,054,334 as I tried to append 1200 rows to my table.  even if I delete the 1200 rows, the autonumber internal counter is incremented so the next try starts at (453,054,334 +1200). 

In the access help file there is a method to store a number to the autonumber field, and it worked for one record, but when I tried my append query, the autonumber was back up there in the stratusphere.   I concatenate those ID fields to make a key for another purpose.  Think of it as he-ID|she-ID=couple-ID.  So you can see why it would be impractical for me to concatenate 2 9-digit numbers!

How can I reset the number for the NEXT records, retaining the ID numbers for rows that are already in the table? 

Any help will be GREATLY appreciated.



-------------
Gary Routh
SheykhObeyd.info



Replies:
Posted By: eksimba
Date Posted: 15 July 2003 at 11:52pm

The short answer is: you can't.

Access intends for the autonumber field to be a number useful only internally to the database engine as a unique record identifier, but not have any other meaning to the programmer. It is bad Access programming practice to try to use an autonumber field for any other purpose (like concatenation with another field) unless you accept the fact that you have little to no control over the value assigned to the autonumber.

In your situation, as long as you have a field with an autonumber value of 453,xxx,xxx the next autonumber will always be 453,xxx,xxx +1. The only way to reset the values would be to remove the records with the offending autonumber values and then compact/repair the database. In theory, after the compact/repair, the next autonumber value will be the highest existing autonumber value +1.

It would be better for your purposes not to use an autonumber at all, but instead create a small procedure which fires upon creation of a new record and assigns a unique record id. That way you can be assured of having complete control over the numbering system...



-------------
- eric


Posted By: Bunce
Date Posted: 16 July 2003 at 7:25am
Originally posted by eksimba eksimba wrote:

 It is bad Access programming practice..

It is bad [insert any database name here] programming practice!



-------------
There have been many, many posts made throughout the world...
This was one of them.


Posted By: ljamal
Date Posted: 16 July 2003 at 8:10am
If the coupleID is so important why not create another table with CoupleID, HeID, and SheID and use the CoupleID reference from that?

-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net