Questions on opening the reports using DoCmd.OutputTo

Posted on 2010-01-05
Last Modified: 2012-05-08
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.
Question by:heyday2004
    LVL 24

    Accepted Solution


    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.


    LVL 24

    Assisted Solution

    by:Bitsqueezer 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.
    LVL 84

    Assisted Solution

    by:Scott McDaniel (Microsoft Access MVP - EE MVE )
    You can open in Hidden:

    DoCmd.OpenReport "name", acViewPreview, , , acHidden

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    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

    Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
    I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
    Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
    Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

    761 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

    12 Experts available now in Live!

    Get 1:1 Help Now