OutputTo problem -- Save Report Filter before OutputTo

OutputTo problem -- Save Report Filter before OutputTo

Post by strive4pea » Sat, 13 Jan 2007 13:51:35


i Dave

you must SAVE the filter with the report before you Output To...here is
a generic procedure you can put into a general module to do this:

'~~~~~~~~~~~~~~~
Sub SetReportFilter( _
ByVal pReportName As String, _
ByVal pFilter As String)

' written by Crystal
' Strive4peace2007 at yahoo dot com

' PARAMETERS:
' pReportName is the name of your report
' pFilter is a valid filter string

' USEAGE:
' SetReportFilter "MyReportname","someID=1000"
' SetReportFilter "MyAppointments", _
"City='Denver' AND dt_appt=#2/14/07#"

On Error Goto Proc_Err

'---------- declare variables
Dim rpt As Report

'---------- open design view of report
' --- and set the report object variable

'use the hidden parameter to open if you don't want to see it
DoCmd.OpenReport pReportName, acViewDesign
Set rpt = Reports(pReportName)

'---------- set report filter and turn it on
rpt.Filter = pFilter
rpt.FilterOn = IIf(Len(pFilter) > 0, True, False)

'---------- save and close the changed report
DoCmd.Save acReport, pReportName
DoCmd.Close acReport, pReportName

'---------- Release object variable
Set rpt = Nothing

Proc_Exit:
Exit Sub

Proc_Err:
msgbox err.description,, _
"ERROR " & err.number & " SetReportFilter"

'press F8 to step thru code and fix problem
'comment next line after debugged
Stop: Resume
'next line will be the one with the error

resume Proc_Exit:

End Sub
'~~~~~~~~~~~~~~~


Warm Regards,
Crystal
*
(: have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*



Dave wrote:
 
 
 

1. Access Macro OUTPUTTO how do I auto say yes to saving file with s.

2. OutputTo in Report Close Event

Hi Everybody,

I'm trying to set up a report so that everytime its printed it is also
outprinted to a file. I'm using the reports activate/deactivate events to
check if it's actually being printed.

Now, in the reports close event I would like to have itself outputted to a
file with the OutputTo method. The problem is, it does not seem possible to
run a report when said report is in middle of running code (specifically, the
Close Event code).

If i try i get an error 2585 -this action cannot be carried out while
processing a form or report event.

The question is, how can this be bypassed? I came up with a few ideas, but
they're all pretty clumsy.
1. Make a table and insert there every report that needs to be outputted and
have a timer spit them every few seconds
2. Maybe store it in a global variable and also have a timer.
3. Disallow printing from preview and only use my own code which also prints
and also outputs.

#1 & #2 are no good because of much to much overhead. Timer every few
seconds. DB reads, writes and deletes all the time (for #2). aside of that it
seems error prone.
#3 is not very user friendly, to say the least.

I'd appreciate if anyone has a good idea and willing to share it.
Thankfully,
YisMan

3. OutputTo: Specify Report Criteria

4. using DoCmd.OutputTo for reports: event code doesn't execute

5. OutputTo Report to Excel - Chart not shown in Excel - Why?

6. report OutputTo with parameter

7. OutputTo Reports

8. Using OutputTo with a report that has OpenArgs

9. Using OutputTo command with NoData Report event

10. Using OutputTo to generate report output by overwriting existing file

11. Marco Outputto to Excel - Object- Report

12. Report with parameter & DoCmd.OutputTo

13. report Outputto rtf missing text

14. Reuse Report and Query and OutputTo - Must be a Way!

15. Report v slow to open in Excel using OutputTo