Access Import From Excel Error

I am importing information from Excel to Access using the DoCmd.TransferSpreadsheet command from with VBA.  The Excel information is being downloaded from SAP and has an issue that Access does not like when importing.  On certain fields like vendor number, that is all numbers, sometimes shows up in Excel as a numeric value, but other times shows up with an error.  The error being "number Stored as Text".  Please see image.  When Access imports this column, it will import the cells with no errors, but will not import the cells with the "number Stored as Text" error.  Access gives the import error message of "Type Conversion Failure" regardless if the field in the Access table is setup as text or as a number.
Please Help, all help will be greatly appreciated.
Gary Excel Error Screen Shot
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

tgtg7Connect With a Mentor Author Commented:
I have spent a lot of time trying different things.  It appears this whole problem relates to the SAP generated Excel files.  If I create other other Excel files from scratch with the same issues, Access has not problem importing the information.   To solve the issue, I ran this vba code over the Excel data from SAP that is to be imported(see code).

I would like to be able to run this code from within Access, meaning the vba code would be housed within Access for a paricual range for a particular workbook.  Any help on this?

Thanks for the help!
Sub MassageImportData()
    Do While IsEmpty(ActiveCell.Value) = False
        If IsEmpty(ActiveCell.Value) = False Then
            Selection.TextToColumns Destination:=ActiveCell, DataType:=xlDelimited, _
                TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
                Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
                :=Array(1, 1), TrailingMinusNumbers:=True
            ActiveCell.Offset(0, 1).Activate
            ActiveCell.Offset(0, 1).Activate
        End If
End Sub

Open in new window

Dale FyeCommented:
When I import from Excel, I almost always setup a dummy table where I do the imports to.  In this table, every field is a text field.  I then run check for invalid values and run another query that inserts the values from this temp field into the actual destination table, doing explicit type conversions as necessary.
Richard DanekeTrainerCommented:
You can edit your import query to convert the field date as well.   A CLng, Ccur, CStr, CVar, or even NZ([field],0) functions can help.  This example looks like a CLng([ExcelFieldName])  would do the trick.  

SQL example    CLng([ExcelFieldName])  as lngExcelFieldName

QBE Field Name example  lngExcelFieldName : CLng([ExcelFieldName])
Above will work or you can DO a check on the fly.
IF Cell isnumber then

copy cell

else  IF cstr(Cell) is number then

copy cstr(cell)

end if

tgtg7Author Commented:
After much trial and error, the above code solved the problem.
All Courses

From novice to tech pro — start learning today.