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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

code to Save an Access Report as an Excel document

Status
Not open for further replies.

dmposey61

Technical User
Mar 26, 2004
11
US
I am trying to find the code that will save an Access Report automatically as an excel document. I am using Access 2000 with Windows XP.

I am trying to add a command button on my form that will export an already created query or report as an excel document. I found the CreateNewDocument Method but that will open up a new document to create. I want to basically do a File - Save As method.

I am a beginner with VB so please be specific and descriptive!

Thank you,
Denise
 
You can export the underlying query of the report to a spreadsheet using a TransferSpreadSheet macro. Open the macro editor, scroll to Transferspreadsheet. Fill in the dialog box that appears at the bottom. Hit F1 for more info and examples.
 
Yes, vbajock is correct in suggesting you use the underlying query of the report. I have used the code below behind a command button to open a query as an Excel doc.

The CurrentProject.Path simply opens the excel doc in the same folder as your database.

Dim eVersion As String
eVersion = CurrentProject.Path & "\" & "OpenOfficesExcelVersion.xls"

DoCmd.OutputTo acOutputQuery, "qryOpenOfficesExcel", acFormatXLS, eVersion, True
 
Thanks vbajock & bandclar!

I had a little trouble with the TransferSpreadSheet macro when it came to Table Name. I've never used this before, so I'm sure it is due to my lack of knowledge. I ended up just exporting report to excel and user can save report on their machine if needed.

Dim stDocName As String

stDocName = "rptName"
DoCmd.OutputTo acReport, stDocName, acFormatXLS, "ReportName.xls", True


This actually works better for what I need to do. Thank you both again!
dmposey61
 
Put either the tablename or a query name in the mis-named table name dialog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top