Results 1 to 3 of 3
  1. #1
    sathishkm21 is offline Novice
    Windows 10 Access 2007
    Join Date
    Jul 2017
    Posts
    6

    Import Text File

    Hi All,

    I have a text file for more than 50 in a specific path. I want to import all the text files in the access. Is there VBA code to do this job.



    Thanks

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    this imports all xl files in the folder via transferspredsheet. Adjust if needed.
    change it to use transfertext, and remember to use the SPEC name.
    docmd.TransferText acImportDelim ,sSpecName,table,vFile, true

    usage:
    ImportAllFilesInDir "f:\folder"

    Code:
    Public Sub ImportAllFilesInDir(ByVal pvDir)
    Dim vFil, vTargT
    Dim i As Integer
    Dim sTbl As String, sSql As String
    Dim fso
    Dim oFolder, oFile
    
    On Error GoTo errImp
    DoCmd.SetWarnings True
    If Right(pvDir, 1) <> "\" Then pvDir = pvDir & "\"
    sTbl = "xlFile"
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set oFolder = fso.GetFolder(pvDir)
    For Each oFile In oFolder.Files
       vFil = oFile
       DoCmd.TransferSpreadsheet acimpolrt, acSpreadsheetTypeExcel12, sTbl, vFil, True
    Next
    Set fso = Nothing
    Set oFile = Nothing
    Set oFolder = Nothing
    DoCmd.SetWarnings True
    Exit Sub
    errImp:
    MsgBox Err.Description, vbCritical, "clsImport:ImportData()" & Err
    Exit Sub
    Resume
    End Sub
    


  3. #3
    sathishkm21 is offline Novice
    Windows 10 Access 2007
    Join Date
    Jul 2017
    Posts
    6
    I want to import text files.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. text file import question.
    By kevinh2320 in forum Access
    Replies: 4
    Last Post: 05-25-2017, 01:11 PM
  2. VBA To Import Text File
    By jo15765 in forum Macros
    Replies: 7
    Last Post: 04-21-2016, 06:28 PM
  3. import text file with text date
    By rody in forum Import/Export Data
    Replies: 5
    Last Post: 09-01-2014, 12:50 AM
  4. import text file over 255 fields
    By belmontj in forum Programming
    Replies: 2
    Last Post: 04-29-2012, 01:53 PM
  5. Import Text File
    By vvasudev in forum Import/Export Data
    Replies: 1
    Last Post: 02-17-2012, 01:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums