table name as same import file name

G

Guest

I am trying to automate the process of importing multiple .txt files. Each txt file needs to be it's own table with the table name equal to the file name
I was going to use the following code but had no clue what to put in the "AccessTable Name" variable

Also, once I have this written, compiled and debugged how do I use it in my .mdb
Thank
Mauree

ChDir ("C:\my files"
strfile = Dir("FileName*.*"
Do While Len(strfile) >
DoCmd.TransferText acImportDelim, "av-txt", "AccessTableName", "c:\MyFiles\" & strfile, Tru
'delete the file (consider moving it to an Archive folder instead.
Kill "C:\my files" & strfil
strfile = Di
Loo

End Su

'CODE ENDS
 
J

Joe Fallon

Use the file name variable as the table name.
You can add the code to a module and give the module a name (NOT the same as
the Sub.)

Public Sub DoImport
ChDir ("C:\my files")
strfile = Dir("FileName*.*")
Do While Len(strfile) > 0
DoCmd.TransferText acImportDelim, "av-txt", strfile , "c:\MyFiles\" &
strfile, True
'delete the file (consider moving it to an Archive folder instead.)
Kill "C:\my files" & strfile
strfile = Dir
Loop
End Sub

Then in the code behind a button on your form you can write:
DoImport


--
Joe Fallon
Access MVP



M Leddy said:
I am trying to automate the process of importing multiple .txt files. Each
txt file needs to be it's own table with the table name equal to the file
name.
 

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