• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 396
  • Last Modified:

Questions on opening the reports using DoCmd.OutputTo

I have a form that users could click on the record and open a report in a separate windows and then they could export (by right click the report) the report to excel file format, etc. The code is as following:

DoCmd.OpenReport "rptTemplate", acViewPreview, , fltSQL
DoCmd.OutputTo acOutputReport, "rptTemplate", acFormatXLS, "C:\temp" & Format(Date, "mmddyyyy") & ".xls"

My questions are:
1. If I don't have the first line: DoCmd.OpenReport ... Then the second line could not be exported succesfully. I want to have a batch command that users will get the exported result directly without opening the preview windows. Is it possible?
2. It says the Outputfile parameter in Outputto command is defined as: "A string expression specifying the full path and name of the destination object. To enter the destination at runtime leave this argument blank."

But when I used this command:     DoCmd.OutputTo acOutputReport, "rptTemplate", acFormatXLS, ""
I still could enter the destination at runtime. What I need to do is to give the users the ability to enter the destination at runtime and then export the report using the predefined file name (generated by today's date). Is it possible?

Thanks for the help.
0
heyday2004
Asked:
heyday2004
  • 2
3 Solutions
 
BitsqueezerCommented:
Hi,

Try it with this:
DoCmd.OutputTo acOutputReport, "rptTemplate", acFormatXLS, , False

This writes the report without previously opening it as preview (no need for DoCmd.OpenReport) and immediately opens a file dialog to enter the target.
Leaving blank means not "", because this is an empty string, it means, no value. The "False" at the end surpresses the start of Excel.

Cheers,

Christian
0
 
BitsqueezerCommented:
...by the way: You used "fltSQL" as parameter to open the report: OutputTo can not submit any parameter to the report, it must run "as is". So maybe this is the reason why you need to open the report before. But you can open it with the parameter "acHidden" as WindowMode so it is not visible.
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You can open in Hidden:

DoCmd.OpenReport "name", acViewPreview, , , acHidden
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now