transfer to excel

Hi.  I need to transfer one of reports from my database to Excel file and transfer should be automatically.
I have following code
DoCmd.OpenReport ("xxx"), acViewPreview

---this line allows to print the report

DoCmd.OutputTo acOutputReport, "xxx", acFormatXLS, "issue.xls", True

---second line of code should transfer report xxx to excel file issue. xls or at least any xls file

Code has an error.  Please help
maximyshkaAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
mbizupConnect With a Mentor Commented:
>However, I need only summary (footer report), not detail section.  Like number of loans, average value for several years, breaked by months.  
If you only need the summary data...

How about using a seperate query to collect summary data such as that shown in your report.  Use aggregate functions like this:

SELECT Count(Loans) as CountOfLoans, Avg(LoanValue) as AvgValue, MonthName
FROM qryYourReportsRecordsource
Group By MonthName

Then export the data using the transferSpreadsheet command like Jim suggested
0
 
mbizupCommented:
Try no parentheses in the first line:

DoCmd.OpenReport "xxx", acViewPreview

The second line looks syntactically correct.  What is the error message?
0
 
Rey Obrero (Capricorn1)Connect With a Mentor Commented:
include a path for the excel file

DoCmd.OpenReport "xxx", acViewPreview

DoCmd.OutputTo acOutputReport, "xxx", acFormatXLS, "C:\issue.xls", True
0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
mbizupCommented:
Both of those lines work fine exactly as you have them posted in an Acc. 2003 sample.  The Excel file gets written to the current directory if no path is specified.  Verify the following:

1.) The exact error message and line of code causing the problem.  Set Break On All Errors if needed.  It it possible that the code causing the error is somewhere else (the report's Load, Activate, Open events for example)?
2.) Double check the name of your report.
3.) Make sure that  Issue.xls is NOT open at the time you run the code.
0
 
maximyshkaAuthor Commented:
Thanks a lot.

Second problem, after I open Excel file I got on Excel file only query headings not actual data from the report.  How to fix that problem?
0
 
mbizupCommented:
That's weird.  I had something similar happen in one of my databases exporting a report (problem with how he report format exported to excel).  It turned out that the data was there, just not visible because the text and cell background color somehow wound up the same in the Excel file (even though it looked good in the original report).  Check into that...

0
 
maximyshkaAuthor Commented:
Hello guys.  Problem is not fixed.  I can't export any kind of reports to Excel.  Data is not visible.
Any suggestions???

I'm looking on property of my reports.  Everything seems to be the same.  However, in one report data is transferred to Excel, in other reports not.
0
 
maximyshkaAuthor Commented:
Disregard previous comment.  Problem was that detail section of the report was not visible.  I need that for display and printing purposes only summary data (everything that I have in footer).  Is there any way to transfer summary data in Excel file???

Problem: data transfered to Excel file only if detail section of the report is visible
0
 
Jim HornConnect With a Mentor Microsoft SQL Server Developer, Architect, and AuthorCommented:
Exporting any Access report to Excel would mean losing the cosmetic formatting of the Access report, and will be extremely ugly.

If all you want to do is transfer the data, then do it using DoCmd.TransferSpreadsheet and use the table/query name that feeds the report, and not the report.

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel97, "Your table or query name here", "Your Excel spreadsheet name here.xls",,"Your Excel tab or named range here, or blank"

{substitute acSpreadsheetTypeExcel97 with whatever is appropriate for your version of Excel}
0
 
maximyshkaAuthor Commented:
Jimborn, I have an Access form.  By clicking the button I want to have two actions:
1) preview report for printing
2) transfer report to excel file

Everything would work if my report has detail section visible
However, I need only summary (footer report), not detail section.  Like number of loans, average value for several years, breaked by months.  

Since I don't have detail section and have only summary
DoCmd.OutputTo acOutputReport, "xxx", acFormatXLS, "issue.xls", True not displaying data in excel file

DoCmd.TransferSpreadsheet method is good only to transfer data from query or table but not from the report

Any suggestions?
0
 
mbizupCommented:
Glad to help :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.