Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2006
    Posts
    43

    Unanswered: Importing txt using Text Wizard

    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 Im 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

  2. #2
    Join Date
    Oct 2014
    Posts
    268
    Provided Answers: 6
    Code:
    Private Sub bImportFiles_Click()
    On Error GoTo bImportFiles_Click_Err
        
        Dim objFS As Object, objFolder As Object
        Dim objFiles As Object, objF1 As Object
        Dim strFolderPath As String
        
        strFolderPath = "C:\Import TXT files\"
        Set objFS = CreateObject("Scripting.FileSystemObject")
        Set objFolder = objFS.GetFolder(strFolderPath)
        Set objFiles = objFolder.files
        
        For Each objF1 In objFiles
            If Right(objF1.Name, 3) = "txt" Then
                DoCmd.TransferText acImportDelim, "TextImportSpecs", "tblImportedFiles", strFolderPath & objF1.Name, False
                Name strFolderPath & objF1.Name As "C:\Archived TXT Files\" & objF1.Name 'Move the files to the archive folder
            End If
        Next
        
        Set objF1 = Nothing
        Set objFiles = Nothing
        Set objFolder = Nothing
        Set objFS = Nothing
        
    bImportFiles_Click_Exit:
        Exit Sub
        
    bImportFiles_Click_Err:
        MsgBox Err.Number & " " & Err.Description
        Resume bImportFiles_Click_Exit
        
    End Sub

    Found this code to import multi text files in one load. After the files load it kicks it the file into an archive folder. You will have to make changes for file names, paths etc.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •