Import many csv files to different table in Access

E

ecc28

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
Dim strFileName As String
Dim strTable As String
I would like to import many csv files with the same file
name as same as table name to Access automatically.

I have tried the following module in Access but run button
is shadow. Please help and advise if any problem. Thanks.

ChDir ("d:\eric\test")
strfile = Dir("FileName*.*")
Do While Len(strfile) > 0
DoCmd.TransferText acImportDelim, strFileName,
strTable, "d:\eric\test" & strfile, True
'delete the file (consider moving it to an Archive
folder instead.)
Kill "d:\eric\test\" & 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