importing text files

D

Dave S

I have a folder of 50+ tab deliminated text files I want
to import into Access. Do I have to do this one file at a
time or is there a way to batch process the files.
Thanks in anticipation
 
A

Anita Mossey

See Help for an explanation of the TransferText method.
The Help explanation shows that TransferText will work
with just one file at a time, meaning that it will have
to be coded 50+ times. It is, however, something that can
be used for batch processing.
 
J

John Nurick

Hi Dave,

If all the files have the same structure and are to be imported into the
same table, it's often simplest to concatenate them into one big file
and import that. At a command prompt, use something like this to
concatenate them:

COPY /B "D:\Folder\*.txt" "D:\Folder\All files.txt"

Alternatively, use code like this (acknowledgements to Joe Fallon) to
import each file individually:

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 ("D:\Folder")
strfile = Dir("*.txt")
Do While Len(strfile) > 0
DoCmd.TransferText acImportDelim, _
"ImportSpecName", "AccessTableName", _
"D:\Folder\" & strfile, True
'delete the file (consider moving it to an Archive folder instead.)
Kill "D:\Folder\" & strfile
strfile = Dir
Loop

End Sub

I have a folder of 50+ tab deliminated text files I want
to import into Access. Do I have to do this one file at a
time or is there a way to batch process the files.
Thanks in anticipation

John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
 
D

Dave S

Hi John,
The concatenate solution worked a treat. I just
wasn't thinking as 'low' as DOS. Thanks
 
J

John Nurick

With text files, the lower the better IMHO!

Hi John,
The concatenate solution worked a treat. I just
wasn't thinking as 'low' as DOS. Thanks

John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
 

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