Can I edit AutoNumber Column in Access?
Asked Answered
H

6

5

I've lost my data in Access base, and I've manage to bring them back but when I copy the values in the table with the AutoNumber Column it increments the numbers. Is there Any way to change it to int and then bring it back to AutoNumber?

Haletta answered 24/6, 2010 at 21:14 Comment(0)
H
1

I've manage to insert the AutoNumber fields by code from c#. I take all the data I need and just inserted in an empty table.

Haletta answered 30/6, 2010 at 7:44 Comment(0)
S
11

Here is how I managed to do this in Access 2010:

  1. Make a backup of your database. (Just to be safe.)
  2. Right-click on the table in the tables list, and select Export->Excel. Accept all defaults.
  3. Open the table in Excel and make the desired change to the autonumber field.
  4. Open the table and delete all rows
  5. Right-click on table in the tables list, and select Import->Excel
    • In the options, choose "Append to table" and select the table. Accept defaults for all other options

This might not be a viable solution for a large table. I don't think Excel can handle more than around 65K rows.

Shifflett answered 10/4, 2012 at 15:4 Comment(0)
I
6

Don't copy the data with the user interface, but append it with a query. Because an Autonumber field is just a long integer with a special default value, you can append to it values that already exist. That doesn't work in the UI, but only in SQL.

An Autonumber field has a few other properties that are different from a normal Long Integer field, but in terms of appending data, those are not relevant. One of those properties is that it is not editable once it's populated, and another is that you can have only one in each table.

Ignatius answered 25/6, 2010 at 23:47 Comment(5)
Someone please explain the downvote, i.e., why this is an erroneous answer.Ignatius
"Autonumber field is just a long integer with a special default value" = a misstatement. I can add two such 'special default value' columns to the table (only one column may have the Autonumber property). I can use UPDATE to change the default value to something else (can't do that to the column with the Autonumber property). The Autonumber column can have a step value other than 1 by creating it using the IDENTITY(<seed>, <step>) in SQL DLL but can't do the same with a column 'special default value'. Need I go on...?Amye
All right. I've changed it. My answer was relevant to the issue of appending data, but not complete.Ignatius
SQL code like: insert into <tablename> (<column 1>, <column2> ...) values ( <value 1>, <value 2>, ...) It's pretty tedious, but worksCredent
@Credent that SQL was the solution for me. Thanks. It might be worth posting as answer since it's less invasive and easier than a lot of the alternatives. I just popped up a VBA immediate window and ran DoCmd.RunSQL "INSERT INTO ..."Chimborazo
H
1

I've manage to insert the AutoNumber fields by code from c#. I take all the data I need and just inserted in an empty table.

Haletta answered 30/6, 2010 at 7:44 Comment(0)
L
1

Make backup of your data table. Delete all data form original table and then do compact & repair your database. By doing this, auto number field will be reset at 1. You may now append your data from backup table.

Lager answered 25/6, 2013 at 13:6 Comment(0)
H
0

How are you bringing the data back? It should be possible to append the data from your table and to keep the existing numbers.

It is necessary however, that you paste from an integer field to the autonumber field. You cannot change a field to autonumber from integer once there is data in the field, but you can change to integer from autonumber.

Halden answered 24/6, 2010 at 21:45 Comment(3)
I've bring the data back combining different tables with similar content and writhing the data back to that Table. But when I insert the records the AutoNumber field increments automatically ignoring my entries.Haletta
Is the data you are brining in an autonumber?Halden
Yes, I've managed to make it AutoNumber, but frankly I don't know how because I've done everything same yesterday. Just coping the data in the table, and it managed.Haletta
C
0

SQL code like

   insert into <tablename> 
   (<column 1>, <column2>, ...) 
   values
   ( <value 1>, <value 2>, ...);

will do the trick if you include the autonumber column in your query. It's pretty tedious, but works. You can switch to SQL mode for any old query to enter this text (usually after preparing it in a text editor), or as @Dominic P points out, you can bring up a VBA immediate window and run DoCmd.RunSQL "INSERT INTO ..." which will give you a better editor experience within Access.

Credent answered 13/2, 2019 at 20:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.