Export filtered query to Excel

kadara

Registered User.
Local time
Today, 07:43
Joined
Jun 19, 2010
Messages
43
Hi,

I have a filtered query (filter a table between 2 dates) and I would like to export this query to an Excel file.
Using this code (because I would like to format some cells) return an error message: "Rut-time error 3061 : Too few parameters. Expected 2."
I tried to export the query to Excel without filters and worked fine.
How could I change the code to accept the filtered query?

Thanks.
 
Why not change the query to a make table then export the table into excel and format etc the result.

Sample would be something like this:

Sub SendToExcel()
Dim xlApp As Excel.Application
Set xlApp = CreateObject("Excel.Application")
DoCmd.SetWarnings = False
DoCmd.OpenQuery "Query4"
DoCmd.SetWarnings=True
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "tblOutPutTable", CurrentProject.Path & "\" & "ExcelFile.xls", True
With xlApp
.Workbooks.Open CurrentProject.Path & "\" & " ExcelFile.xls"
.Sheets(1).Select
.Cells.AutoFit
.visible=True

End With
End Sub
 

Users who are viewing this thread

Back
Top Bottom