Connecting Tech Pros Worldwide Forums | Help | Site Map

Importing entire set of Files from a Common Folder using VBA

Newbie
 
Join Date: Apr 2007
Posts: 25
#1: May 7 '07
Hello;

I have an application where a set of text files, all with the same record format, are contained in a folder. I wish to read in these physical files as one logical file to update my table. I have created an Import Specification for the record format. Do you know how I can import the entire contents of the folder using the Invalid Specification?

Thanks,
Gregg

JConsulting's Avatar
Expert
 
Join Date: Apr 2007
Location: Houston
Posts: 601
#2: May 7 '07

re: Importing entire set of Files from a Common Folder using VBA


something like so

Expand|Select|Wrap|Line Numbers
  1.  Function ImportTXT()
  2. Dim FSO As Object
  3.     Set FSO = CreateObject("Scripting.FileSystemObject")
  4.     Dim Fl As Object
  5.     strfolder = "C:\"
  6.  
  7.     strFile = Dir(strfolder & "\*.txt", vbNormal)
  8.     Do While strFile <> ""
  9.         If strFile <> "." And strFile <> ".." Then
  10.         DoCmd.TransferText acImportDelim, "Import Spec", "TableName", strFile, False, ""
  11.         End If
  12.         strFile = Dir()
  13.     Loop
  14.     Set FSO = Nothing
  15. End Function
Newbie
 
Join Date: Apr 2007
Posts: 25
#3: May 8 '07

re: Importing entire set of Files from a Common Folder using VBA


Great! Thank you! That worked to perfection!
JConsulting's Avatar
Expert
 
Join Date: Apr 2007
Location: Houston
Posts: 601
#4: May 8 '07

re: Importing entire set of Files from a Common Folder using VBA


Quote:

Originally Posted by GreggaR0und

Great! Thank you! That worked to perfection!

Happy to help
J
Reply