Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Reset Autonumber values in Access DB
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Reset Autonumber values in Access DB

 Post Reply Post Reply Page  12>
Author
theSCIENTIST View Drop Down
Senior Member
Senior Member


Joined: 31 July 2003
Location: United Kingdom
Status: Offline
Points: 440
Post Options Post Options   Thanks (0) Thanks(0)   Quote theSCIENTIST Quote  Post ReplyReply Direct Link To This Post Topic: Reset Autonumber values in Access DB
    Posted: 13 January 2004 at 4:42am

I have WWF running out an Access DB, I have made changes over the years to it and added many new fields to store all sorts of information, I am now cleaning up the forums and will start from the beginning with no users, categories, forums, topics and threads.

The problem is that the auto-number fields still add the IDs to a higher value and not from 1,2 and so on, ie. last user had an ID of 480, all users are erased, but for every new user added, it gets 481, 482 and so on, how can I reset this to start from the beginning?

Does anyone knows how to do reset the database AutoNumber fields on Access DBs?

Back to Top
aalavar View Drop Down
Groupie
Groupie


Joined: 08 December 2003
Status: Offline
Points: 46
Post Options Post Options   Thanks (0) Thanks(0)   Quote aalavar Quote  Post ReplyReply Direct Link To This Post Posted: 13 January 2004 at 8:26am

I've always had the same problem in access... If you change the field to a number though, you can query the database and get the maximum value, then add 1 to it, then insert using that number, but I don't think that it will work with the autonumbers.

Back to Top
zaboss View Drop Down
Senior Member
Senior Member


Joined: 20 August 2002
Location: Romania
Status: Offline
Points: 454
Post Options Post Options   Thanks (0) Thanks(0)   Quote zaboss Quote  Post ReplyReply Direct Link To This Post Posted: 13 January 2004 at 8:34am

Just rename the old autonumbered field to something else, make it instead of auto-numbered to number and set a new auto-numbered field with the old one's name. Set it as primary key and incremental and it should start with 1.

Although sometimes for me it starts with 22, I never figured out why.

Cristian Banu
Soft 4 web
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 13 January 2004 at 11:42am
it starts with 22 because you delete previous values. The autonumber is incremented everytime regardless of earlier values.

E.g. You have a table with 3 records in and an ID column going from 0 to 2. if you delete record 2 when you insert the next record it will not replace record 2. E.g. the ID column now looks like

[ID]
----
0
1
3
Back to Top
zaboss View Drop Down
Senior Member
Senior Member


Joined: 20 August 2002
Location: Romania
Status: Offline
Points: 454
Post Options Post Options   Thanks (0) Thanks(0)   Quote zaboss Quote  Post ReplyReply Direct Link To This Post Posted: 13 January 2004 at 11:45am
Nope. I do create a brand new table, so there are no previouse deleted record. And, sometimes, it does not start with 1 as it is supposed to be, but with 22. And everytime it starts with other number but 1 it starts with 22. Not 23, not 45, not whatever, but only 22.
Cristian Banu
Soft 4 web
Back to Top
theSCIENTIST View Drop Down
Senior Member
Senior Member


Joined: 31 July 2003
Location: United Kingdom
Status: Offline
Points: 440
Post Options Post Options   Thanks (0) Thanks(0)   Quote theSCIENTIST Quote  Post ReplyReply Direct Link To This Post Posted: 14 January 2004 at 4:25am

So I need to rename the AutoNumber fields and create a new ID AutoNumber, I'm assuming that after that I can delete the old renamed field.

I have to repeat the process to all IDs AutoNumbers, isn't there another way to quickly reset all this fields at database level?

Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 14 January 2004 at 9:32am
Following is the information about how to change the starting value of an
incrementing AutoNumber field in Microsoft Access Help. Hope it helps!

Change the starting value of an incrementing AutoNumber field
For a new table that contains no records, you can change the starting value
of an AutoNumber field that has its NewValues property set to Increment to
a number other than 1. For a table that contains records, you can also use
this procedure to change the next value assigned in an AutoNumber field to
a new number.

Create a temporary table with just one field, a Number field; set its
FieldSize property to Long Integer and give it the same name as the
AutoNumber field in the table whose value you want to change.
How?

In Datasheet view, enter a value in the Number field of the temporary table
that is 1 less than the starting value you want for the AutoNumber field.
For example, if you want the AutoNumber field to start at 100, enter 99 in
the Number field.


Create and run an append query to append the temporary table to the table
whose AutoNumber value you want to change.
How?

Note   If your original table has a primary key, you must temporarily
remove the primary key before running the append query. Also, if your
original table contains fields that have the Required property set to Yes,
the Indexed property set to Yes (No Duplicates), or field and/or record
ValidationRule property settings that prevent Null entries in fields, you
must temporarily disable these settings.

Delete the temporary table.


Delete the record added by the append query.


If you had to disable property settings in step 3, return them to their
original settings.
When you enter a record in the remaining table, Microsoft Access uses an
AutoNumber field value 1 greater than the value you entered in the
temporary table.

Note   If you want to compact the database after changing the starting
AutoNumber value, make sure to add at least one record to the table first.
If you don't, when you compact the database, the AutoNumber value for the
next record added will be reset to 1 more than the highest previous value.
For example, if there were no records in the table when you reset the
starting value, compacting would set the AutoNumber value for the next
record added to 1; if there were records in the table when you reset the
starting value and the highest previous value was 50, compacting would set
the AutoNumber value for the next record added to 51.
Back to Top
psycotik View Drop Down
Groupie
Groupie


Joined: 27 November 2003
Status: Offline
Points: 73
Post Options Post Options   Thanks (0) Thanks(0)   Quote psycotik Quote  Post ReplyReply Direct Link To This Post Posted: 14 January 2004 at 7:15pm
If you go changing field names and types watch your links. You might stuff up integrity.
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.