Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a Button to export a query to Excel

Status
Not open for further replies.

McLiguori

Technical User
Mar 27, 2003
90
IT
Hi Everyone and Happy Holidays!

Apoligies. I had posted this question previously in the wrong forum.

I need to create a button on a form that will export a query (MyQuery) in Excel 97 - 2002 format. The name of the new Excel File is not that important, although it would be good if it was MyQuery.xls or even if it asked for the name I would like to give it. I would like the Excel file to end up in the same directory as the .mdb file is located.

What code do I need to enter into the button's "on click" to make this happen.

I can do it manually by going in the database window to the query, right clicking then selecting export. I need to automate it with a button.

Thanks once again.

McLigs
 
Have a look at the TransferSpreadsheet method in Access' help files.

Hope it helps,

ALex

Ignorance of certain subjects is a great part of wisdom
 
I agree with alex here is the code:

Code:
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "[Export Query Name]", "C:\[DirectoryName]\[Excel Workbook Name].xls"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top