Change datatype when importing Excel file into Access

27,241

Solution 1

This may be caused by Excel Jet driver default settings. Check out the following registry key and change it's value from default 8 to 0, meaning "guess column data type based on all values, not just first 8 rows."

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Excel]
"TypeGuessRows"=dword:00000000

Please, tell if this works.

Solution 2

There are a couple of ways to do this. The most straightforward way is to convert the .xls file to a .csv file in Excel, so you can import into Access using the Import Text Wizard, which allows you to choose the data types of every column during the import.

The other benefit to doing this is that the import of a csv (or text) file is so much faster than the import of an xls file. If you're going to do this import more than once, save the import setup settings as an import specification. (When in the Import Text Wizard, click on the "Advanced..." button on the bottom left, then click on "Save As" and give a specification name to save the changes you just made.)

Solution 3

open your excel file. In Home tab change format from General to Text. then import into access

Share:
27,241
user3930756
Author by

user3930756

Updated on July 09, 2022

Comments

  • user3930756
    user3930756 almost 2 years

    Is there any way to change the default datatype when importing an Excel file into Access? (I'm using Access 2003, by the way).

    I know that I sometimes have the freedom to assign any datatype to each column that is being imported, but that could only be when I'm importing non-Excel files.

    EDIT: To be clear, I understand that there is a step in the import process where you are allowed to change the datatype of the imported column.

    In fact, that's what I'm asking about. For some reason - maybe it's always Excel files, maybe there's something else - I am sometimes not allowed to change the datatype: the dropdown box is grayed out and I just have to live with whatever datatype Access assumes is correct.

    For example, I just tried importing a large-ish Excel file (12000+ rows, ~200 columns) in Access where column #105 (or something similar) was filled with mostly numbers (codes: 1=foo, 2=bar, etc), though there are a handful of alpha codes in there too (A=boo, B=far, etc). Access assumed it was a Number datatype (even after I changed the Format value in the Excel file itself) and so gave me errors on those alpha codes. If I had been allowed to change the datatype on import, it would have saved me some trouble.

    Am I asking for something that Access just won't do, or am I missing something? Thanks.

    EDIT: There are two answers below that give useful advice. Saving the Excel file as a CSV and then importing that works well and is straightforward like Chris OC says. The advice for saving an import specification is very helpful too. However, I chose the registry setting answer by DK as the "Accepted Answer". I liked it as an answer because it's a one-time-only step that can be used to solve my major problem (having Access incorrectly assign a datatype). In short, this solution doesn't allow me to change the datatype myself, but it makes Access accurately guess the datatype so that there are fewer issues.

  • user3930756
    user3930756 over 15 years
    Well, it does work in that Access is now guessing the datatype more intelligently. However, I still do not have the power to change the datatype to whatever I please during the import process. I do realize that I may have no other option, though. If that is the case, I'll accept this as the answer.
  • Rishabh Kumar
    Rishabh Kumar over 3 years
    Hi Deepak. Your answer lacks details and examples. Please check on how to write awesome answers here : stackoverflow.com/help/how-to-answer