Can someone please help? I am trying to import all text files in a folder to an Access dB, but I am getting an error when I run the code below.
Error 3011 -"The Microsoft Office Access database engine could not find the object (filename). Make sure the object exists and that you spell the name and the file path name correctly",
I am passing the full path name to the transfer function using a textbox named txtImportPath1 on a form. The textbox is populated by browsing to the folder and picking up the full path.
The error message picks up the name of the first text file in this folder that it says it cannot find.
Please help!
Code:
strFolderPath = Me.txtImportPath1
Set objFS = CreateObject("Scripting.FileSystemObject")
If objFS.FolderExists(strFolderPath) = False Then
MsgBox strFolderPath & " Folder Not Found ", vbCritical, "File Import"
Exit Sub
End If
Set objFolder = objFS.GetFolder(strFolderPath)
Set objFiles = objFolder.files
For Each objF1 In objFiles
If Right(objF1.Name, 3) = "TXT" Then
On Error Resume Next
' Drop previous Temp table before linking to the new text file
' If table not found go to next line
DoCmd.RunSQL "DROP TABLE tbl_TempWKS"
' Link to the text file and import file to the specified table using the specs provided
DoCmd.TransferText acLinkDelim, "WKSpecs", "tbl_TempWKS", objF1.Name, True