Link to home
Start Free TrialLog in
Avatar of Davisro
DavisroFlag for United States of America

asked on

Type Conversion Failure on Import from CSV

When importing a CSV file into Access, I received a type conversion error on a number field with 10digits. Access assigned Long Integer to the field but the data did not import. I read here
https://social.technet.microsoft.com/Forums/ie/en-US/ee617aa1-4369-4fb5-82c3-30f481098ce4/access-import-text-file-fails-with-type-conversion-failure?forum=officeitproprevious
that going to the Advanced tab and changing the Code Page from OEM United States to Western European (Windows) would solve the problem and it did. Does anyone understand why?
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

At a guess, it changes the way the Wizard identifies the field type.

 Access makes an educated guess as to the field type based on a sampling of the first few rows.  Sometimes it guess wrong.   A common one is on US postal codes, which are 5 digits.  But the US also has zip + 4, so some data will look like this:

12345-6789

 with a dash, meaning you need to import it as a text field.   You also loose a leading zero if it imports it as a number.

 What and why the code page adjustment triggers a change though I have no idea.

  The real fix of course is to adjust the field types.

Jim.
Avatar of Davisro

ASKER

Hi Jim. Sure, but the field type seems correct. The 10 digit numbers in Excel are formatted as General. When I pasted them into notepad (multiple excel files totaling 600k records), and then imported the file, Access assigned Long Integer to the field which seemed appropriate, yet, the data then failed to import
Hi,

Within the Import wizard, you can define the data type for each column.
Choose either Double, or Text data type (whatever fit your needs).
but the field type seems correct. The 10 digit numbers in Excel are formatted as General.
Beware that Excel and Access don't handle data type the same way. Access is less tolerant.
Avatar of Davisro

ASKER

Fabrice, Alright...so what would be the appropriate data type for a 10 digit number? I'm sure text would work but I don't understand why Long Integer doesn't work
Long Integer data types are 32 bits and range from -2147483648 to 2147483647, so not all 10 digits numbers will fit in.

If you need to keep a numeric value, Double type, else Text type.
ASKER CERTIFIED SOLUTION
Avatar of Mark Edwards
Mark Edwards
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
O.k.  sorry, you don't NEED to set up an import specification for CSV, but it avoids/fixes these kinds of issues.
Avatar of Davisro

ASKER

Of course. So Double or Decimal would work. Thanks for pointing this out.
Also, if you use VBA to Import .CSV with the TransferText function, you'll need an import specification for that....