Import Routine

  • Thread starter Thread starter Paul Hammond
  • Start date Start date
P

Paul Hammond

I have a very brief procedure I am running to import a
collection of text files.

Public Function ProcessFiles()

Dim myFSO As New Scripting.FileSystemObject
Dim myfolder As Scripting.Folder
Dim myFile As Scripting.file

Set myfolder = myFSO.GetFolder(Server_Path)

For Each myFile In myfolder.Files

DoCmd.SetWarnings False
DoCmd.TransferText acImportDelim, "Import",
"tblImport", myFile.Name, True

Next

MsgBox "Finished"

End Function

I have been getting the error message below.

Runtime Error 3011
"The Microsoft Jet database engine could not find
object 'sample1.txt'. Make sure object exists. etc..."

If I manually import just one of these files and then run
the same code it works perfectly. Any ideas why?

TIA

Paul Hammond
Richmond, VA
 
Hi Paul,

Try .Path instead of .Name.

Public Function ProcessFiles()

Dim myFSO As New Scripting.FileSystemObject
Dim myfolder As Scripting.Folder
Dim myFile As Scripting.file

Set myfolder = myFSO.GetFolder(Server_Path)

For Each myFile In myfolder.Files

DoCmd.SetWarnings False
DoCmd.TransferText acImportDelim, "Import",
"tblImport", myFile.Name, True

Next

MsgBox "Finished"

End Function
 
Back
Top