Export query results

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a customised toolbar which includes the 'New query' and 'Export'
button.
The purpose of the 'New query' button will be allow users to run their on
query and uexport to excel using the 'Export' button. However I am finding
that you need to save the query before you can export the results. Is there a
way around this?

Thanks
 
Hi,

I have a customised toolbar which includes the 'New query' and 'Export'
button.
The purpose of the 'New query' button will be allow users to run their on
query and uexport to excel using the 'Export' button. However I am finding
that you need to save the query before you can export the results. Is there a
way around this?

Thanks

You don't need to save the query, however you'll need to save the
excel spreadsheet before opening it.

insert this piece of code in your modules, in this example it runs a
query named qryBook against my database and saved the results in excel
format: C:\BookReports\BookReport_08112007.xls

'\Run query and save results in Excel
format-------------------------------------------------------------
strQuery = "qryBook"

If DCount("*", strQuery) > 0 Then

'open the Query
DoCmd.OpenQuery strQuery

'save the Query in Excel format
DoCmd.OutputTo acOutputQuery, strQuery, acFormatXLS, _
"C:\BookReports\BookReport_" & Format(Now, "mmddyyyy") &
".xls"

'close the Query
DoCmd.Close acQuery, strQuery
End If
 
Where is the code inserted. I have the standard access run button in my
customised toolbar. Do I need to create a new button? If so is there any way
that I can create a button in the customised toolbar?

Thanks.
 
Back
Top