Import text files with different names

Import text files with different names

Post by Lynn » Wed, 29 Sep 2004 04:59:29

I have an application that imports text files into
tables. Currently I'm doing it with "transfertext" in a
macro. My macro imports the text file, runs a couple of
queries on it and creates my tables. The problem is that
I have to specify a file name and path in the macro which
means my user has to copy his text files and rename them
to my file name and put them where my macro is looking
for them. I would like my user to be able to select the
text file from wherever and not have to rename it. Any


Import text files with different names

Post by Joe Fallo » Wed, 29 Sep 2004 13:16:04

How to Import all Files in a Folder:

Private Sub btnImportAllFiles_Click()
'procedure to import all files in a directory and delete them.
'assumes they are all the correct format for an ASCII delimited import.
Dim strfile As String

ChDir ("c:\MyFiles")
strfile = Dir("FileName*.*")
Do While Len(strfile) > 0
DoCmd.TransferText acImportDelim, "ImportSpecName", "AccessTableName",
"c:\MyFiles\" & strfile, True
'delete the file (consider moving it to an Archive folder instead.)
Kill "c:\MyFiles\" & strfile
strfile = Dir

End Sub

Joe Fallon
Access MVP


Import text files with different names

Post by John Nuric » Wed, 29 Sep 2004 14:45:55

Hi Lynne,

The code here lets you use the standard File Open/Save dialog:

This gives the Browse for Folder dialog instead:

On Mon, 27 Sep 2004 12:59:29 -0700, "Lynne"

Please respond in the newgroup and not by email.