Results 1 to 3 of 3
  1. #1
    darls15 is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2019
    Posts
    8

    Automatically exporting and appending multiple queries to individual tabs in Excel

    Hi All
    I currently use the DoCmd.TransferSpreadsheet sample code below to export multiple queries to a single Excel workbook on a weekly basis.
    It works well in that each query is output to a individual tabs in the one workbook.
    However, what I'd ultimately like to do, instead of creating a new file each time I export, is to have the data from each of the queries automatically append to the respective worksheets (query1, query2, query3).
    I would like the data to be placed after the last row of data on each worksheet and the workbook to automatically save and close without being prompted.
    I have searched extensively but can't seem to find anything that I have the skills to be able to modify that will do this.
    Would someone please be able to help me with this?
    Many thanks
    darls15

    ~~~~~~~~~~~~~~~~~~~

    Sub ExportQueryData()

    Dim strFilePath As String
    strFilePath = "C:\Output"

    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "exp_query1", strFilePath + "alldata.xlsx", True, "query1"
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "exp_query2", strFilePath + "alldata.xlsx", True, "query2"


    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "exp_query3", strFilePath + "alldata.xlsx", True, "query3"

    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    See if something here http://accessmvp.com/KDSnell/EXCEL_Export.htm gets you close.

    Should be able to use either automation or CopyFromRecordset to export to an existing Excel file. What you need in addition is code to locate next blank row to use as start location. Something like:

    Code:
        LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row + 1 'Finds the last blank row
    
    Workbooks can be unmanageable when they get too much data.
    Excel can link to Access table or query.
    Excel VBA can pull data from Access table or query.
    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
    darls15 is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2019
    Posts
    8
    Hi June7
    Thanks for taking the time to get reply and thanks for the advice.
    I'm now thinking I was going about this all wrong and will look into storing it in tables and linking from Excel instead.
    Thanks again
    darls15

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

Similar Threads

  1. Replies: 22
    Last Post: 12-29-2015, 10:41 PM
  2. Replies: 12
    Last Post: 12-17-2012, 12:47 PM
  3. Export Queries to Excel tabs with Save as Dialog box
    By deepanadhi in forum Import/Export Data
    Replies: 1
    Last Post: 05-16-2012, 10:36 AM
  4. Form with Tabs and multiple external queries
    By chris.williams in forum Forms
    Replies: 3
    Last Post: 11-16-2011, 06:20 PM
  5. Replies: 7
    Last Post: 08-05-2011, 10:59 AM

Tags for this Thread

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