I am trying to use an Insert Into query to select data from an Excel file and insert it into an Access table. The issue I'm having is one of the Excel columns can be letters, numbers or both. I would like to select the data as text, but I seem to only get blanks for the text and text/number entries. If I sort the Excel file so that a text item is in the first row, all data is converted. I have tried the following:
strSQL = "INSERT INTO tblImport ([TIMS Company Code]) " & _
"SELECT [TIMS Company Code] " & _
"FROM [Excel 8.0;HDR=YES;DATABASE=" & xlPath & "].[Manual Entry$];"
=========================================================================
strSQL = "INSERT INTO tblImport ([TIMS Company Code]) " & _
"SELECT CStr([TIMS Company Code]) " & _
"FROM [Excel 8.0;HDR=YES;DATABASE=" & xlPath & "].[Manual Entry$] " & _
"WHERE [TIMS Company Code] IS NOT NULL;"
=========================================================================
strSQL = "INSERT INTO tblImport ([TIMS Company Code]) " & _
"SELECT (CAST([TIMS Company Code]) AS TEXT) " & _
"FROM [Excel 8.0;HDR=YES;DATABASE=" & xlPath & "].[Manual Entry$];"
I have also looked into something called "schema.ini" but it seems a little over my head.
I appreciate any help someone can provide.
Jason
As you have found out, Access tries to be helpful, and guess the data type based on the first 8 rows.
There are two workarounds:
After a lot more research I have learned a lot, but not found a solution. For anyone who stumbles down this road, here are a few things worth knowing:
IMEX=1
will work if there is at least 1 row of text in the first 8[HKLM\Software\Microsoft\Jet\4.0\Engines\Excel