By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,384 Members | 671 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,384 IT Pros & Developers. It's quick & easy.

Importing entire set of Files from a Common Folder using VBA

P: 25

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?

May 7 '07 #1
Share this Question
Share on Google+
3 Replies

Expert 100+
P: 603
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:\"
  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
May 7 '07 #2

P: 25
Great! Thank you! That worked to perfection!
May 7 '07 #3

Expert 100+
P: 603
Great! Thank you! That worked to perfection!
Happy to help
May 8 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.