Results 1 to 4 of 4
  1. #1
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Dec 2010
    Posts
    209

    Export Multiple Query Results To One Excel Workbook

    I want to export 5 queries to one workbook. For example, I want qryMaster to go to a worksheet called Master, qryOne to go to a worksheet called One, qryTwo to go to a worksheet called two etc etc

    I always use this to export a query result to excel - is this able to be altered to accomplish my above desired result or do i need to go a different route?

    Code:
        Dim qrySQL As String
        Dim qdf As QueryDef
    
    
    
    
        qrySQL = "SELECT ......;"
        Set qdf = CurrentDb.CreateQueryDef("qryTest", qrySQL )
        DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "qryTest", CurrentProject.Path & "\Test.xlsx", True


  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    Can't use TransferSpreadsheet for this. Will need Excel automation. For ideas review http://accessmvp.com/KDSnell/EXCEL_MainPage.htm

    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
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Dec 2010
    Posts
    209
    Eeek - looks like i'm after the sample code Create a Query and Export multiple "filtered" versions of a Query (based on data in another table) to separate Worksheets within one EXCEL file via TransferSpreadsheet (VBA)

    hurts my head looking at it

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    Okay, I quess TransferSpreadsheet is still usable. But as you recognize, does get complicated.

    However, in your case looks like don't really need recordset and looping and QueryDefs to build queries. You already have 5 queries built, so run 5 DoCmd.TransferSpreadsheet commands.

    I just did a quick test and it works.

    Try it, let us know how it goes.

    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: 07-14-2018, 07:22 AM
  2. Replies: 4
    Last Post: 01-12-2017, 01:29 AM
  3. Replies: 2
    Last Post: 10-15-2014, 12:30 PM
  4. Replies: 2
    Last Post: 05-16-2013, 07:43 PM
  5. Replies: 1
    Last Post: 04-30-2012, 05:10 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
  •  
Other Forums: Microsoft Office Forums