Import text files with different names

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
 
J

Joe Fallon

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top