Import text files with different names

  • Thread starter Thread starter Lynne
  • Start date Start date
L

Lynne

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
ideas?

TIA
Lynne
 
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
Loop

End Sub
 
Back
Top