Batch Imort...

doran_doran

Registered User.
Local time
Today, 10:13
Joined
Aug 15, 2002
Messages
349
Hi,

I have about 1400 text files (fixed text delimited) and all have same layout and they are all in same folder.

How can I shot a command in access to import all those 1400 text files information in one table? I dont want to import them manually. I already have the fixed width import design for one plan. But I need to do a batch import.

ANY HELP WILL BE APPRECIATED
 
The following Sub should do what you require:
Code:
Public Sub BatchImport(tableName As String, ByVal filePath As String, _
    specName As String)

    Dim bFileName As String

    If right(filePath, 1) <> "\" Then filePath = filePath & "\"

    bFileName = Dir(filePath & "*.txt")

    Do While bFileName > ""
        Debug.Print "Importing: " & filePath & bFileName
        DoCmd.TransferText acImportFixed, specName, tableName, _
            filePath & bFileName, True
        bFileName = Dir
    Loop

    Debug.Print "Done!"

End Sub

For example, to import all the files with a .txt extension from C:\MyFolder\ into MyTable, using MyImportSpec, call the sub thus:

BatchImport "MyTable", "C:\MyFolder\", "MyImportSpec"


See if this works for you.
 

Users who are viewing this thread

Back
Top Bottom