Paste query results to Excel

B

BillyRogers

I'm trying to convert a db I inherited at work. It's loops through a list of
filters for a query and saves the result of each one as a separate
spreadsheet using the docmd.OutpuTo method.

I'm trying to change the code to put the results of all 11 query results in
one spreadsheet instead of 11 different spreadsheets. I've got the code
written to build the spreadsheet, add and name the extra sheets needed.

All I need to do now is paste the results of the query "Preview" each time
it loops in the currently selected sheet. I just don't don't know how to
paste the query into the sheet.

thanks,

Billy


Private Sub cmdAutoExport_Click()
Dim BusinessCounter, Rounds As Integer
Dim Preview, FilePath, Business, File As String



txtTest.Value = listBusiness.ListCount
Rounds = 0


'----------------------RATE-FOR EXPORT------------------------------
'---------------------------------------------------------


Set xlapp = New Excel.Application
Set appWorkBook = xlapp.Workbooks.Add

appWorkBook.Worksheets.Add
appWorkBook.Worksheets.Add
appWorkBook.Worksheets.Add
appWorkBook.Worksheets.Add
appWorkBook.Worksheets.Add
appWorkBook.Worksheets.Add
appWorkBook.Worksheets.Add
appWorkBook.Worksheets.Add


appWorkBook.Worksheets(1).Name = "F"
appWorkBook.Worksheets(2).Name = "K"
appWorkBook.Worksheets(3).Name = "T"
appWorkBook.Worksheets(4).Name = "420"
appWorkBook.Worksheets(5).Name = "421"
appWorkBook.Worksheets(6).Name = "424"
appWorkBook.Worksheets(7).Name = "430"
appWorkBook.Worksheets(8).Name = "431"
appWorkBook.Worksheets(9).Name = "434"
appWorkBook.Worksheets(10).Name = "440"
appWorkBook.Worksheets(11).Name = "444"
xlapp.Visible = True
appWorkBook.SaveAs "N:\FeeRateSummary.xls"


For BusinessCounter = 0 To listBusiness.ListCount - 1
frmFeeRev.Value = 1
listBusiness.RowSource = "F;K;T;420;421;424;430;431;434;440;444"
listBusiness.Requery
listBusiness.Selected(BusinessCounter) = True
Business = "UPDATE [*UpdateMonth] SET [*UpdateMonth].[Fee Business] = '"
& listBusiness.Column(0, BusinessCounter) & "';"
DoCmd.RunSQL Business

Preview = "FeeRatePreview"

Rounds = Rounds + 1
Business = DLookup("[Fee Business]", "[*UpdateMonth]")
File = Trim(Business) & ".xls"
FilePath = DLookup("[Path]", "[*UpdateMonth]") & "\FeeRate\" &
DLookup("[FeeMonth]", "[*UpdateMonth]") & "-" & File
txtTest.Value = FilePath

Sheets(BusinessCounter + 1).Select


'!!!! Here is where I need help. I need to paste the results of the query
Preview in the currently selected sheet.


' DoCmd.OutputTo acOutputQuery, Preview, acFormatXLS, FilePath --old
way that I want to change


Next BusinessCounter


--
Billy Rogers

Dallas,TX

Currently Using SQL Server 2000, Office 2000 and Office 2003
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top