How To Import Text File From Code
Posted on 2013-01-07
I am using this code to attempt an import of a fixed width .csv text file:
Private Sub cbImport_Click()
Dim strFileName As String
Dim strSQL As String
Dim strImportSpec As String
If IsNull(Me.txtFile) = True Then
MsgBox "You must find a file for import!", vbExclamation, "File Required"
strSQL = "DELETE GL_ImportTable.* FROM GL_ImportTable"
strFileName = Trim(Me.txtFile)
strImportSpec = "Import_GL"
DoCmd.TransferText acImportFixed, "Import_GL", "GL_ImportTable", strFileName, True
I have used it with both a variable and the string shown for the Specification name and in each case I get a message that says:
"The text file specification "Import_GL" does not exist."
Obviously it does, and I have even copied the name right out of the specification list into the code.
Any help will be appreciated.