Results 1 to 4 of 4
  1. #1
    aggar is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2012
    Posts
    2

    Automatic Import of multiple CSV file in Access with

    Hi,

    I need to import 15 csv files into access every month. I have location of all those files listed in a table in the same access DB but i'm not sure how to incorporate them in a macro I have written to import one of those files:

    Function Macro_TransferCsvFileTo_RatesTradeData()
    On Error GoTo Macro_TransferCsvFileTo_RatesData_Err
    DoCmd.TransferText acImportDelim, "Import_Spec_tbl_RatesData", "tbl_RatesData", "c:\Documents and Settings\aggaura\Desktop\WIP\XML\DB_JOH_FI_2011123 0.csv", True, ""

    Macro_TransferCsvFileTo_RatesData_Exit:
    Exit Function


    Macro_TransferCsvFileTo_RatesData_Err:
    MsgBox Error$
    Resume Macro_TransferCsvFileTo_RatesData_Exit
    End Function

    where c:\Documents and Settings\aggaura\Desktop\WIP\XML\DB_JOH_FI_2011123 0.csv is the file name I want to be replaced by each of the file listed by me in the other access table.

    Could someone help please?

    Many Thanks

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    I don't know macros well enough to be sure, but think you will have to use VBA. I don't know if looping code can be defined in a macro. And what you need to do is open a recordset of the table and loop through the records, read the path/filename from the field and execute the import on each.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    aggar is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2012
    Posts
    2
    Yeah - I was able to do that - see below - but I'm having to specify all the file names in a separate table - is there a way to just specify a particular directory and automatically import the filenames?

    Function Macro_TransferCsvFileTo_RatesData()
    On Error GoTo Macro_TransferCsvFileTo_RatesData_Err
    Dim filename As String
    Dim filecount As Integer
    Dim loopcount As Integer
    filecount = DMax("[ID]", "tbl_FileNames_Query")

    For loopcount = 1 To filecount

    filename = DLookup("[CompleteFileName]", "tbl_FileNames_Query", "[ID] = " & loopcount)

    DoCmd.TransferText acImportDelim, "Import_Spec_tbl_RatesData", "tbl_RatesData", filename, True, ""
    'DoCmd.TransferText acImportDelim, "DB_JOH_SWAPS_20111230 Import Specification", "tbl_RatesData", filename, True, ""

    Next

    MsgBox ("Files Imported - Check for Import Errors in DB")
    Macro_TransferCsvFileTo_RatesData_Exit:
    Exit Function
    Macro_TransferCsvFileTo_RatesData_Err:
    MsgBox Error$
    Resume Macro_TransferCsvFileTo_RatesData_Exit
    End Function

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    You need some code that will get all the files in a directory.
    Google: VBA import all files in a directory
    Here is one:
    http://www.eraserve.com/tutorials/MS..._All_Files.asp
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 5
    Last Post: 12-01-2011, 05:38 PM
  2. import txt file with multiple headers
    By vojinb in forum Import/Export Data
    Replies: 9
    Last Post: 07-25-2011, 10:37 AM
  3. Replies: 1
    Last Post: 05-23-2011, 02:15 AM
  4. Replies: 4
    Last Post: 07-15-2010, 05:58 PM
  5. Splitting an Excel File into Multiple Access Tables on Import
    By TheWolfster in forum Import/Export Data
    Replies: 4
    Last Post: 04-29-2010, 04:52 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