View Full Version : Combine DoCmd.OutputTo Lines of Code
brorick
02-12-2007, 02:08 PM
Does anyone know how I can combine the following two lines of code.
DoCmd.OutputTo acOutputReport, "Rpt_Analyst 3rd Qtr List_Employee Profile_Param", "SnapshotFormat(*.snp)", "c:\AuditReport.snp"
DoCmd.OutputTo acOutputReport, "Rpt_Analyst 3rd Qtr List_Employee Profile_Param", acFormatRTF, "C:\AuditReport2Word.rtf"
As you can see I am referencing the same report for both lines of code, but I am exporting it as both a snapshot and RTF file. I would prefer that the report only run once as this is a parameter report. Therefore if the coding is not combined, the report will run twice which would require the user to enter the parameter twice. Any help is greatly appreciated. :doh: Thank you.
Hello again, this is an odd one, you can't combine the 2 lines of code, the VBA Editor just won't allow it.
I can think of a way around it though.
For one thing I do not like Parameter Queries/Reports as they do not give you the same control as using a Form to input the Filter.
If you were to use a form or at least an "Input" message box then you could use the code to store the users "entry" in a temporary Table.
The query for the Report can then use this as it's filter and can be Run as many times as you want without asking for any further inputs.
Another possibility would be setting the Input to a VB Variable and use that with SQL instead of an actual query, or as a filter in the Report activation code.
brorick
02-14-2007, 06:36 AM
Hello OBP. As usual you are an ace at coming up with solutions that I hadn't thought about. Presently I do utilize a form that pops up and then requires that the user make a selection that is used as a filter for the report. The selection made by the user will satisfy the first line of code:
DoCmd.OutputTo acOutputReport, "Rpt_Analyst 3rd Qtr List_Employee Profile_Param", "SnapshotFormat(*.snp)", "c:\AuditReport.snp"
Based on your recommendation how would I then refer to the user's selection so that I can use it in the second line of code? For now I will continue to experiment so that I can try and replicate your recommendation. OBP, thanks again.
Well it depends, if you are using the "Filter" from the Form's input in the criteria row of a query then you should be able to run the second Report using the Form's code without the Parameter being asked for.
As long as the Form remains open the query will run without asking for the parameter.
So you should have the Pop Up Form's code running both Reports in the After Update of the Pop up Form's Input Field or Combo if you are using one and use the Forms field as the Criteria Row of the Query, like this -
[forms]![pop up form name]![user input field]
where "pop up form name" is the name of your popup form and "pop up form name" is the name of the field or combo.
brorick
02-14-2007, 09:13 AM
Thanks. I will give it a try.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.