?
Solved

transfer to excel

Posted on 2006-10-31
11
Medium Priority
?
1,208 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 560 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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
 

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 66

Assisted Solution

by:Jim Horn
Jim Horn earned 720 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 720 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

743 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