Autonumber values being appended to after Import

Posted on 2011-03-10
Last Modified: 2012-05-11

I have an MDB, in which I'm running a VB script (OnClick) that will import data from a csv.
But I've noticed, when I successfully import the data, my autonumber ID field has the number 3775 appended to the beginning of it.

Note: I'm not importing every field from the csv, just a few.

This is some rough code.

'Transfers data into temporary table in Access
DoCmd.TransferText transfertype:=acImportDelim, _
      tablename:="tblMonthlyData", _
      FileName:="D:\Documents\Examples\Monthly Data.csv", _

Open in new window

'Inserts data from temp table into "live" table
Currentdb.Execute "INSERT INTO MyLiveTable(Col1, Col2, Col3) SELECT Col1, Col2, Col3 FROM MyTemporaryTable"

Open in new window

The autonumber field has changed like this....
2065, 2068, 37752069, 37752070, 37752071...

How do I get rid of this?
Question by:--TripWire--
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
LVL 85

Accepted Solution

Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 175 total points
ID: 35100165
That's not a number that is "appended", that's the actual AutoNumber value.

Why this occurs is hard to say, but it smacks of corruption. I'd immediately make a backup of your database, then try these fixes:

1) Compact the database. You didn't mention which version you're using, but if you need help with this please let us know
2) Build a new, blank database and import everything into it.

This generally will clear up any corruption (if that's the trouble).

Author Comment

ID: 35100239
Thanks for the reply - I did both steps that you highlighted, including re-importing that data using the same code.  Still giving me those 3775 numbers at the beginning.
LVL 85
ID: 35100272
Is this the actual code you're using:

Currentdb.Execute "INSERT INTO MyLiveTable(Col1, Col2, Col3) SELECT Col1, Col2, Col3 FROM MyTemporaryTable"

Or is this just an example? When I suggested you use that in your other question, I also included instructions that you would need to change this to match the Tables and Fields in your project.

Unless you have a table named "MyLiveTable" with columns named Col1, Col2 and Col3, and a table named MyTemporaryTable with those same columns, this code won't work.

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now


Author Comment

ID: 35100515
Yes, I've changed the code to match the situation.  The import works, because everything is transferring over fine, except for the autonumber field.  But even then, the last four digits are accurate.  Only the 3775 at the beginning comes from no where.

I can't really copy and paste the actual code I have, because I've been programming this from a terminal window on a server.
LVL 85
ID: 35100733
Are you inserting into the AutoNumber field? It's certainly possible to do that, and this could account for your anamoly.

Further: The value of the AN field should play no role in your data. It's nothing more than a surrogate key (at best) that points to a specific record in your table.

Expert Comment

ID: 35101500
In this commandline:
Currentdb.Execute "INSERT INTO MyLiveTable(Col1, Col2, Col3) SELECT Col1, Col2, Col3 FROM MyTemporaryTable"

if Col1 is your AN field, this can cause this problem. You don't have to include Autonumberfield in your SQL statement. So try this:

Currentdb.Execute "INSERT INTO MyLiveTable(Col2, Col3) SELECT Col2, Col3 FROM MyTemporaryTable"

Author Comment

ID: 35102437
No, I'm not inserting into my Autonumber field.  I'm just using it as an arbitrary identifier.  But I am using this number to identify the entries outside of this database.  So I'm not too fond of it being that big (at least yet).

AN is auto-filling those numbers upon import.
LVL 85
ID: 35107368
<So I'm not too fond of it being that big (at least yet).>

Can you explain what the trouble is with the size of the numbers? An AutoNumber field can contain any value between (appx) -2.15 BILLION and + 2.15 BILLION. Thats roughly 4.3 billion numbers available to you via the AN field in Access. You would reach the size limit of an Access database (2 gb) loooooooong before you "run out" of AutoNumber values.

And your AutoNumber field should have absolutely no "data value" - that is, it should not provide any functionality to that record other than providing a pointer to it. It should not be what defines the record as "unique" (although it can be a Unique index), and it should not be used for sequential ordering (since it's not guaranteed to be sequential, only unique).

What version of Access are you using? If you're using 2003 or below, make certain that you've fully updated the Jet engine. There were some issues with AutoNumber fields with earlier versions of Jet.

Jet Updates:

Author Comment

ID: 35108272
I'm not using the AN to complete any operations, however, this database is not going to be used by me, the person that will use it uses that number as a reference outside of the computer for that record.  (The paper record).  Why do you not recommend the AN as a unique identifier?

The reason I don't want the numbers to jump that high yet, is because, when the database actually gets to the size of 3775xxx, I don't want my MDB to try and force the new records' AN to be the same as a previous record.  I will ask for the Jet to be updated, and let you know if this helps the problem.

Author Comment

ID: 35108437
I just realized they are running MS Access 2002 on MS Server 2003 SP1...therefore this particular update won't apply.  Do I have any other recourse?

Author Comment

ID: 35109162
Is there a way to trim the leading 4 characters of AN?

Author Comment

ID: 35110172
Nevermind.  It was corruption after all.  Started a brand new DB with the same fields and the info exports over properly now without affecting the AN field.

Author Comment

ID: 35110174
Thank you!
LVL 85
ID: 35110542
<Why do you not recommend the AN as a unique identifier?>

An AutoNumber field can be a Unique index, but the ONLY function of an AutoNumber field should be as a surrogate key. In other words, it's nothing more than a quick and easy way to "point" at a specific record. AN fields should have no "data value" - that is, it should not matter whether the database system assigns a value of 100 or 324,575. Your system (i.e. your user interface) should not really expose this number, since it is meaningless to the end user.

You should use OTHER columns to insure that your record is unique - for example, if you are storing Customer records, you might use the CustomerName + TelephoneNumber + Country to insure that a specific Customer record is unique in your database. However, many people (including me) don't advocate the use of multi-column Primary Key indexes. So to insure data consistency while still give you a reliable and easy method to relate this record with others, you'd use an AutoNumber field as your "Primary Key", while still maintaining that 3 column index. YOu could then use the AN field to relate your Customer records to other data.

< the person that will use it uses that number as a reference outside of the computer for that record.  (The paper record).  >

In almost every case, this is a bad idea. Users (i.e. humans) expect values to be sequential, and an Access AN field is NOT guaranteed to be sequential - and it's quite common for gaps to be introduced into the AN field, due to the way Access manages the disposition of the AN fields.

<when the database actually gets to the size of 3775xxx, I don't want my MDB to try and force the new records' AN to be the same as a previous record>

This wouldn't happen anyway - Access would simply skip those values (assuming you're not dealing with a corrupt db, of course) and move to the next available number.


Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question