locked
How do Import multiple CVS??? RRS feed

  • Question

  • I need to import multiple CSV files into ONE access table.... how do I do this?

    ol

    Thursday, August 24, 2017 8:39 PM

All replies

  • One at a time? Are you asking manually or in code?
    Thursday, August 24, 2017 8:51 PM
  • Hi,

    Are file names with path of CSV files provided in advance?  Are they saved in the same folder?
    Is file extension ".csv"?
    You should provide the further details about what you want to do.
    Regards,

    Ashidacchi

    Friday, August 25, 2017 12:14 AM
  • Hi mwareing,

    Has your issue been resolved? If not, it would be helpful if you could share us more information.

    If you want to manually import multiple csv files, it is impossible. Access database does not support this feature.

    If you want to achieve by code, I suggest you loop through the files and import them:

    DoCmd.TransferText TransferType:=acImportDelim, TableName:="tblImport", _
        FileName:="C:\MyData.csv", HasFieldNames:=true

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, August 29, 2017 8:04 AM
  • I can imagine that there are several ways to do this.  Try it this way.

    Option Compare Database 
    Option Explicit 
    
    Function DoImport() 
    
     Dim strPathFile As String 
     Dim strFile As String 
     Dim strPath As String 
     Dim strTable As String 
     Dim blnHasFieldNames As Boolean 
    
     ' Change this next line to True if the first row in CSV worksheet 
     ' has field names 
     blnHasFieldNames = True 
    
     ' Replace C:\Documents\ with the real path to the folder that 
     ' contains the CSV files 
     strPath = "C:\Documents\" 
    
     ' Replace tablename with the real name of the table into which 
     ' the data are to be imported 
    
     strFile = Dir(strPath & "*.csv") 
    
    
     Do While Len(strFile) > 0 
           strTable = Left(strFile, Len(strFile) - 4) 
           strPathFile = strPath & strFile 
           DoCmd.TransferText acImportDelim, , strTable, strPathFile, blnHasFieldNames 
    
    
     ' Uncomment out the next code step if you want to delete the 
     ' EXCEL file after it's been imported 
     '       Kill strPathFile 
    
           strFile = Dir() 
    
     Loop 
    
    
    End Function 


    MY BOOK


    • Edited by ryguy72 Wednesday, August 30, 2017 10:55 PM
    Wednesday, August 30, 2017 12:10 PM
  • Whoops, I didn't know you wanted all the files to go into ONE single table.  Ok, try this.



    Dim strPathFile As String, strFile As String, strPath As String Dim strTable As String, strBrowseMsg As String Dim blnHasFieldNames as Boolean ' Change this next line to True if the first row in EXCEL worksheet ' has field names blnHasFieldNames = False strBrowseMsg = "Select the folder that contains the CSV files:" strPath = "C:\your_path_here\" If strPath = "" Then MsgBox "No folder was selected.", vbOK, "No Selection" Exit Sub End If ' Replace tablename with the real name of the table into which ' the data are to be imported strTable = "tablename" strFile = Dir(strPath & "\*.csv") Do While Len(strFile) > 0 strPathFile = strPath & "\" & strFile

    DoCmd.TransferText acImportDelim, , strTable, strPathFile, blnHasFieldNames

    ' Uncomment out the next code step if you want to delete the ' EXCEL file after it's been imported ' Kill strPathFile strFile = Dir() Loop




    MY BOOK


    • Edited by ryguy72 Wednesday, August 30, 2017 11:14 PM
    Wednesday, August 30, 2017 11:09 PM