Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Autonumber values being appended to after Import

Posted on 2011-03-10
14
Medium Priority
?
442 Views
Last Modified: 2012-05-11
Hello,

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", _
      hasfieldnames:=True

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?
0
Comment
Question by:--TripWire--
[X]
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
14 Comments
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 700 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).
0
 

Author Comment

by:--TripWire--
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.
0
 
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.



0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

Author Comment

by:--TripWire--
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.
0
 
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.
0
 

Expert Comment

by:alikemalkul
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"
0
 

Author Comment

by:--TripWire--
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.
0
 
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:
http://support.microsoft.com/kb/239114
0
 

Author Comment

by:--TripWire--
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.
0
 

Author Comment

by:--TripWire--
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?
0
 

Author Comment

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

Author Comment

by:--TripWire--
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.
0
 

Author Comment

by:--TripWire--
ID: 35110174
Thank you!
0
 
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.

0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

670 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