Hello!
I would appreciate it if someone could explain why I'm getting Run time error '3011' The Microsoft Access database engine could not find the object "C:\MyPath\MyFile 01.txt" when running the below code:
The code should import the data from all txt files from folder "C:\MyPath\" with the name MyFile*.txt (for example MyFile 01.txt, MyFile 02.txt.....) into table MyTable. When I run the code, I get the Run time error '3011' The Microsoft Access database engine could not find the object "C:\MyPath\MyFile 01.txt" message.
If I rename the file to MyFile.txt there is no error and I can import the data.
I would appreciate it if someone could explain why I'm getting Run time error '3011' The Microsoft Access database engine could not find the object "C:\MyPath\MyFile 01.txt" when running the below code:
Code:
Sub LoopThroughFiles()
'to import all MyFiles*.txt data to table MyTable
Dim StrFile As String
Dim Path As String
StrFile = Dir("C:\MyPath\MyFile*.txt")
Path = "C:\MyPath\"
Do While Len(StrFile) > 0
Debug.Print StrFile
'adds records to Table
DoCmd.TransferText acImportDelim, "MyImportSpec", "MyTable", Path & StrFile, True
StrFile = Dir
Loop
MsgBox "The end", vbInformation, "Import"
End Sub
The code should import the data from all txt files from folder "C:\MyPath\" with the name MyFile*.txt (for example MyFile 01.txt, MyFile 02.txt.....) into table MyTable. When I run the code, I get the Run time error '3011' The Microsoft Access database engine could not find the object "C:\MyPath\MyFile 01.txt" message.
If I rename the file to MyFile.txt there is no error and I can import the data.