11

I don't need to reset the AutoNumber value like this question, but rather would like to first set the number to:

1001

Which then increments like normal:

1001

1002

1003

...

How do I go about doing this in Access 2010?

3
  • 5
    Not an answer, but a warning: Autonumber is not designed to be managed in this way. I've seen countless people try it. It never works because the DB will do weird things incrementing sometimes (failed writes still increment the number, for example). Autonumber does not guarantee that the record numbers will be consecutive. Indeed, in rare cases it won't even guarantee the number will be unique. It's very useful for creating a primary key for a small table. It's a little risky for large tables. It's absolutely awful for using as an actual data field. He
    – Bacon Bits
    Commented May 24, 2011 at 20:42
  • @BaconBits... what then is AutoNumber meant to be used for? Commented May 24, 2011 at 20:59
  • Rest of @BaconBits's comment: nce you see articles like this when something goes pear-shaped because people expect Autonumber to be something it's not. If you need to generate numbers in this manner, write the queries and such in the DB to do it properly yourself.
    – Pylsa
    Commented May 24, 2011 at 20:59

7 Answers 7

19

Although Access doesn't offer this function natively, it can be achieved through a query, like the following:

CREATE TABLE TableThatIncrements
(
Id AUTOINCREMENT(1001,1)
)

This will create a single table that's called "TableThatIncrements" with a single column, named "Id". You can now use the table editor to add properties and/or other columns.

Change

AUTOINCREMENT(x,y)

to suit your needs, where x is the initial increment number and y is the number to increment with. So AUTOINCREMENT(100,5) will yield: 100, 105, 110, 115, etc.

If you want to alter an existing table, use the following query. Make sure that specific table's tab is closed so Access can lock it down and alter it.

ALTER TABLE TableThatIncrements
   ALTER COLUMN Id AUTOINCREMENT(1001,1)

You can run a query in Access by doing the following:

  1. Go to the "Create" tab and click "Query Design"
    enter image description here

  2. Just close the window that appears which asks you to select tables, we don't need that.

  3. Go to the "Design" tab and click the button with the arrow until you get a textual input screen. (By default, it says SELECT;).
    enter image description here

  4. Delete the default text and paste the above query.

  5. Click "Run".
    enter image description here

2
  • 1
    good answer, but that creates a new table... or am I wrong? Can this be done within an already created table? Commented May 24, 2011 at 20:42
  • 1
    @KronoS Updated my answer
    – Pylsa
    Commented May 24, 2011 at 20:48
3

1- Create table1 2- Go to create ------- > design query. 3- Close table 4- Go to SQl from above. 5- Past this code.

ALTER TABLE [TABLE1] ALTER COLUMN [Id] COUNTER (8982,1)

4
  • This appears to be the same as the accepted answer except for the use of a different keyword (and the other one is much better formatted).  Is your answer really different?  Can you explain how?  Is your answer better?  Why? Please do not respond in comments; edit your answer to make it clearer and more complete. Commented Jun 27, 2018 at 15:22
  • @Scott Actually they are a little different: ALTER COLUMN Id AUTOINCREMENT(1001,1) and ALTER COLUMN [Id] COUNTER (8982,1) see the word AUTOINCREMENT and COUNTER but they both work as expected Commented Jan 20, 2020 at 4:18
  • 1
    @willyw: Right; I said “the same … except for the use of a different keyword”. Commented Jan 20, 2020 at 5:17
  • @Scott ops yes you are right... I was reading too fast sorry ;-) Commented Jan 20, 2020 at 5:40
1

This website has a very simple way to start your autonumber with whatever number you wish: http://www.fmsinc.com/microsoftaccess/AutoNumber%20Field/Creating.asp

You create a query with an expression which tells the autonumber field to change

"First, run this query:

INSERT INTO tblName ( ID ) SELECT 999 AS Expr1

Where tblName is the table name, and ID is the name of the AutoNumber field.

Then, run a second query to delete the row that you inserted:

DELETE FROM tblName WHERE ID=999;

(Alternatively, you can simply open the table and manually delete the row that you inserted.)

Now, the next record added to the table is assigned the value 1000.

This method works with a new table, or with a table whose AutoNumber has not yet reached the Seed value. (Of course, the ID field for existing rows will not be changed, but subsequent rows will start with 1000.)"

0

You have to trick Access because it assumes you're not interested in an autonumber different than the one it provides.

You'll need to start the table out with the custom autonumber, which will require some setup. But once it's going you can just continue adding from there.

Google "access change autonumber start" and you'll find several options for doing this. Most rely on creating an append query to modify the field.

Create the first table that contains the counter type field that you want to start on another number. Don't enter any records.Create a second table, with a single long integer number type field that has the same name as the counter field in the first table. Create a record in the second table by entering a number one less than the number you want to start the counter at in the first table. Create an append query, to append the one record in the second table to the first table, and run it Delete the second table, delete the record that you appended to the first table, and start entering data.

From MVPS.org: http://access.mvps.org/access/tables/tbl0005.htm

If you don't feel like building an append query, you could always set up the table and copy and paste 1000 lines of dummy data from excel, delete the records until you get to number 1001, and go on from there.

UPDATE: Adding explanation for reason

The reason behind autonumber being only set to start from 1 is that the autonumber field is meant to be used as an internal reference field, and in good database practice, should not generally be used in any publicly visible form. It is used in cases where there is not already a unique item in a given table to create a unique entry by which the table can be searched and indexed.

2
  • There's gotta be an easier way to doing this.... Commented May 24, 2011 at 20:20
  • I suppose the good news is that if you need to create several tables with such an autonumber, you can simply create one, save it in a "template" database file, and just copy it to new database files as you need it. Commented May 24, 2011 at 20:28
0

This is a pretty old thread, but still pops up as a top three Google search result.

One reason a user may want to change the value of an autonumber field is to correct an error caused by database editing. When an administrator may want to make some major changes to a front end of a database, that admin might make copies of all related tables, and redirect a development copy of the front end to these back ends. If the changes are sufficient enough, he may just replace the production copy of the front end with his copy, redirecting all linked tables after testing.

No problem, right? Well, the autonumber incrementation stays with the front end. So if the production side just incremented the autonumber by 50 or 500 or 5000 numbers while the admin was working on the copy, then the new production copy will by retrying those same numbers and won't be able to enter items into those fields, one at a time, until it gets "in the clear". Copy 50, 500, or 5000 rows of excel data and try to paste it in. It will error on each line (be sure to suppress further messages when it pops up), but the autonumber will increment by that amount and you're good to go again. If you're using autonumbers in this way, it would be advised to increment the numbers to whatever the production db is at before overwriting it with your development copy.

This is also a way to start your autonumber at something higher than 1. Like the old days of setting the page visits counter at 17,479 on your Geocities homepage, when really it was only visited 16 times. By you.

0

A simple way to achieve something similar is to have an Autonumber field (eg "ID") and a second Calculated field (eg "ItemID") and enter the formula "1000+[ID]" for the calculated field. This new field will now automatically track the Autonumber field, but will start from 1001 instead of 1.

0

I believe it could be achieve to your custom increment range by first creating a hidden table which will keep the initial gap of auto increments begining from zero to your choice , eg. that table will keep the 0 to 1050 Then you commence at of increments 1055 ,1060, 1065 etc. You will then hide this portion of data from the table. Hope this helps. Seems like Access was designed to look initially from zero, as conflicts will arise.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .