Results 1 to 3 of 3

Import multiple .csv files and appending file names on import

  1. #1
    New_to_this is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Posts
    2

    Import multiple .csv files and appending file names on import

    HI,


    I have found the code below to import multiple .csv files into one table but I now need to append the file name to each file once its been imported so I can keep a track, if this is possible and as I'm very new to all this could you insert the code into the one below, so I cant make any mistakes, my
    folder is called "originals" and located on my C:\ and it contains 5 .csv file called 1, 2, 3, 4 , 5

    I also need to drop the headers after the first file is imported..

    many thanks in advance




    Sub Import_multiple_csv_files()


    Const strPath As String = "C:\Addresspoint" 'Directory Path
    Dim strFile As String 'Filename
    Dim strFileList() As String 'File Array
    Dim intFile As Integer 'File Number

    'Loop through the folder & build file list
    strFile = Dir(strPath & "*.csv")
    While strFile <> ""
    'add files to the list
    intFile = intFile + 1
    ReDim Preserve strFileList(1 To intFile)
    strFileList(intFile) = strFile
    strFile = Dir()


    Wend
    'see if any files were found
    If intFile = 0 Then
    MsgBox "No files found"
    Exit Sub
    End If
    'cycle through the list of files & import to Access
    'creating a new table called MyTable
    For intFile = 1 To UBound(strFileList)
    DoCmd.TransferText acImportDelimi, , _
    "PETA VSK Merged", strPath & strFileList(intFile)
    'Check out the TransferSpreadsheet options in the Access
    'Visual Basic Help file for a full description & list of
    'optional settings
    Next
    MsgBox UBound(strFileList) & " Files were Imported"
    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    7,032

  3. #3
    New_to_this is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Posts
    2
    thanks ranman256 but i mentioned yetserday the below,

    Hi Sorry,

    thanks for this but as I said before I'm a total newbie when I paste your query I get path not found, now I know its something really silly. the folder my files are located in is called "originals" on my C:\ and it contains 5 .csv file called 1, 2, 3, 4 , 5
    the error message I get is "path not found"

    once again, my apologies for this will soon pick it up!!

    if you could assist me further would be appreciated?

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

Similar Threads

  1. Replies: 12
    Last Post: 04-09-2017, 08:56 AM
  2. Replies: 4
    Last Post: 06-05-2015, 02:05 PM
  3. Import Procedure - Variable File Names
    By Ada01 in forum Programming
    Replies: 5
    Last Post: 03-03-2015, 04:43 PM
  4. Import File Names
    By cassidym in forum Import/Export Data
    Replies: 3
    Last Post: 01-11-2011, 02:19 PM
  5. Replies: 4
    Last Post: 07-15-2010, 04:58 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
  •  
Tech Forums: Microsoft Office Forums