Solved

transfer to excel

Posted on 2006-10-31
11
1,201 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
0
Comment
Question by:maximyshka
11 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 17847091
Try no parentheses in the first line:

DoCmd.OpenReport "xxx", acViewPreview

The second line looks syntactically correct.  What is the error message?
0
 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 140 total points
ID: 17847133
include a path for the excel file

DoCmd.OpenReport "xxx", acViewPreview

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

Expert Comment

by:mbizup
ID: 17847213
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
 

Author Comment

by:maximyshka
ID: 17849760
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
 
LVL 61

Expert Comment

by:mbizup
ID: 17850013
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:maximyshka
ID: 17852271
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
 

Author Comment

by:maximyshka
ID: 17852338
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
 
LVL 65

Assisted Solution

by:Jim Horn
Jim Horn earned 180 total points
ID: 17853144
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
 

Author Comment

by:maximyshka
ID: 17853736
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
 
LVL 61

Accepted Solution

by:
mbizup earned 180 total points
ID: 17854736
>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
 
LVL 61

Expert Comment

by:mbizup
ID: 17870681
Glad to help :-)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now