Type Conversion Failure on Import from CSV

Davisro
Davisro used Ask the Experts™
on
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?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Jim Dettman (EE MVE)President / Owner
Most Valuable Expert 2017
Most Valuable Expert 2012

Commented:
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.
DavisroBudget Analyst

Author

Commented:
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
Fabrice LambertConsulting
Distinguished Expert 2017

Commented:
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).
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Fabrice LambertConsulting
Distinguished Expert 2017

Commented:
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.
DavisroBudget Analyst

Author

Commented:
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
Fabrice LambertConsulting
Distinguished Expert 2017

Commented:
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.
Chief Technology Officer
Commented:
For the simple reason of the defined range for a Long Integer (copied from Microsoft support website page):
"Long Integer — For integers that range from -2,147,483,648 to +2,147,483,647"
a 10-digit number can go higher.
for .CSV import, you need to setup an import specification.  You need one for .CSV export.
Also, the Import Specification details recorded in the "MSysIMEXSpecs" table (has specification name) and its child table "MSysIMEXColumns" (field details) are much more than what are exposed to you by the wizard.  You can edit the data in this table to any data type for any column you want.  I built my own specification editor form so I could get full exposure to, and editing capability of, import/export specifications.
Mark EdwardsChief Technology Officer

Commented:
O.k.  sorry, you don't NEED to set up an import specification for CSV, but it avoids/fixes these kinds of issues.
DavisroBudget Analyst

Author

Commented:
Of course. So Double or Decimal would work. Thanks for pointing this out.
Mark EdwardsChief Technology Officer

Commented:
Also, if you use VBA to Import .CSV with the TransferText function, you'll need an import specification for that....

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial