Import from Excel to MS Access ignores text entries from column that has both text and numbers

Viewed 25

I have a function that automatically imports data from an Excel spreadsheet to an MS Access table. It works successfully with other imports, but I've just called it from a new import process and find that only numeric entries are being imported, even though the destination field is short text. I think that an assumption is being made based on the initial entries in this field, which are numeric.

Below is the function I'm using.


Public Function Import_Excel(strIMPORTTABLE As String, strFILE As String, strRANGE As String) As Boolean
    On Error GoTo ErrorHandler
    
    Run_SQL "Delete * From " & strIMPORTTABLE
    DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, strIMPORTTABLE, strFILE, True, strRANGE
    
    Import_Excel = True
    
EndRoutine:
    Exit Function
    
ErrorHandler:
    MsgBox Err.Number & " - " & Err.Description
    Import_Excel = False
    Resume EndRoutine
End Function

The parameters I'm feeding it are the table name (which is correct), filename and path (also correct) and the range "Sheet1!A1:B50000", which is large enough for what I want. It's only two fields, the first is a unique identifier and the second is a text field that contains some numeric entries.

How can I make the import treat the second column as text?

Thanks.

0 Answers
Related