We help IT Professionals succeed at work.

transfer to excel

maximyshka
maximyshka asked
on
Medium Priority
1,220 Views
Last Modified: 2011-10-03
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
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
Try no parentheses in the first line:

DoCmd.OpenReport "xxx", acViewPreview

The second line looks syntactically correct.  What is the error message?
CERTIFIED EXPERT
Top Expert 2016
Commented:
include a path for the excel file

DoCmd.OpenReport "xxx", acViewPreview

DoCmd.OutputTo acOutputReport, "xxx", acFormatXLS, "C:\issue.xls", True

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
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.

Author

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?
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
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...

Author

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.

Author

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
Jim HornSQL Server Data Dude
CERTIFIED EXPERT
Most Valuable Expert 2013
Author of the Year 2015
Commented:
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}

Author

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?
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013
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
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
Glad to help :-)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.