Importing txt using Text Wizard

TBC

Registered User.
Local time
Today, 08:26
Joined
Dec 6, 2010
Messages
145
I have a list of 30 files I need to import into my access database. The files in the folder are named
1. Txt
2. Txt
3. Txt
4. Txt
5. Txt
6. Txt
7. Txt
8. Txt

When I did the first import I did it by doing an import text file, located the file 1.txt. The Import Text Wizard opened and I picked Fixed With so I could break out the information myself.
After dividing that information I hit advanced and changed the field name to match what they should be. Next, then it ask me to save Import Steps and I said yes.

First I’m wondering how I can use the saved import to import this file again using the text wizard
Second, how can I set it so it imports a numbers of files, maybe one or maybe all 30?
Third, how difficult would it be to all the file name in the first or last column?

Thank you for taking your time and your help
 

Attachments

import all the files in the folder by passing the folder name.
usage: ImportAllCsvFile("c:\folder\folder2")


Code:
   'import all files in folder
'------------------
Public Sub ImportAllCsvFiles(ByVal pvDir)
'------------------
Dim vFil, vTargT
Dim i As Integer
Dim sTbl As String, sSql As String
Dim tdf As TableDef
Dim vSheet, vQry, oFolder, oFile

sTbl = "xlFile"    'linked xl file to import

On Error GoTo errImp
Set Db = CurrentDb

Select Case True
 Case pvDir = ""
    MsgBox "No source folder given", vbCritical, "Error"
 
Case Else
    DoCmd.Hourglass True
    DoCmd.SetWarnings False
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set oFolder = fso.GetFolder(pvDir)
    For Each oFile In oFolder.Files
        If InStr(oFile, ".txt") > 0 Then         'only csv files
            vFil = pvDir & oFile.Name
                     'import the text file
            DoCmd.TransferText acImportDelim, sSpecName, sTbl, vFil , True

        End If

    Next  'file
End Select

Set oFile = Nothing
Set oFolder = Nothing
DoCmd.Hourglass False
DoCmd.SetWarnings True
Exit Sub

errImp:
MsgBox Err.Description, vbCritical, "ImportAllCsvFiles()" & Err
Exit Sub
Resume
End Sub
 
Thanks Ranman256, where would I put the location

C:\Users\Desktop\Daily Work Project Folder\Rene Time Card

Can you show me by using the DB I attached
 

Users who are viewing this thread

Back
Top Bottom