[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 389
  • 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

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

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