Results 1 to 20 of 66

Thread: Importing multiple txt files, but including extra data from file name

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,297
    Location
    This code will import all the CSV files from a Folder.

    Dim FileNm, FilePathName, Path, FileNameList() As String
        Dim FileCount As Integer
        DoCmd.SetWarnings False
        Path = Me.FilePath
        FileNm = Dir(Path & "")
        Search_path = Path ' where ?
        Search_Filter = "*.CSV" ' what ?
        Docname = Dir(Search_path & "" & Search_Filter)
        Do Until Docname = "" ' build the collection
             MsgBox Docname
             FilePathName = Path & Docname
             DoCmd.TransferText transferType:=acImportDelim, SpecificationName:="pp OUTINGS", TableName:="pp OUTINGS", FileName:=FilePathName, hasfieldnames:=True
             Docname = Dir
        Loop
        DoCmd.SetWarnings True
        MsgBox "Updates Complete"
        Exit Sub
        errorcatch:
        MsgBox Err.Description
    Note that this VBA is run from a form which has a field called Filepath which is used to identify which folder you want to use, you could replace the me.Filepath with the actual path to your folder.

    Also the DoCmd.TransferText has an Import specification called "pp OUTINGS" which you will not need unless you have an import spec.
    The data is then placed in a table called "pp OUTINGS"

    Try this code by modifying it to suit your folder and table and then repost if you do so.
    Last edited by Aussiebear; 02-09-2025 at 03:01 PM.

Posting Permissions

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