Solved

Export queries to multiple excel worksheets in the same workbook using VBA.

Posted on 2006-11-21
2
925 Views
Last Modified: 2008-02-01
Hi,

I would like to export a number of access queries to different worksheets in the same workbook using Access VBA.  What's the best method?



0
Comment
Question by:geraintcollins
2 Comments
 
LVL 34

Accepted Solution

by:
jefftwilley earned 50 total points
Comment Utility
Create a table to put your query names into and use this.

Function OutToExcel()
Dim rsOUT As DAO.Recordset
Dim strOutPutFile As String
Dim strSpecTable As String
Dim strLoc As String
Dim strCo As String

    strOutPutFile = "C:\Whatever.xls"   '<----------Your spreadsheet name

' JT Prepare to create a fresh output file by deleting any old files if they exist
    If FileExist(strOutPutFile) Then
        Kill strOutPutFile
    End If

' JT Create the Output Excel spreadsheet
    strSQL = "Select * from MyQueryTable;"  '<-----------Your query table
    Set rsOUT = CurrentDb.OpenRecordset(strSQL)
    Do Until rsOUT.EOF
        strOutQry = rsOUT!("MyQueryFieldName")    '<---------the name of the field in the query table
        DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel97, strOutQry, strOutPutFile, True
    rsOUT.MoveNext
    Loop
    rsOUT.Close
    Set rsOUT = Nothing

End Function
0
 

Author Comment

by:geraintcollins
Comment Utility
very good - thanks mate
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now