Export/Print Filtered Report (1 Viewer)

xyba

Registered User.
Local time
Today, 23:36
Joined
Jan 28, 2016
Messages
189
I've tried to find a solution to this but can't find anything conclusive, so I need some help with my code please.

I have a form that has three . One combo to select a report, another combo to select a department to filter by, and a button to create the filtered report.

I have the below code on the button onclick event which produces a view of the filtered report as required:

Code:
Private Sub CreateReportBtn_Click()
DoCmd.OpenReport reportName:=RepNameBox, view:=acViewReport, whereCondition:="dept='" & Me.DepNameBox & "' OR 'All'='" & Me.DepNameBox & "'"
DoCmd.Maximize
Me.RepNameBox = Null
End Sub

How would I change this code to directly export the filtered report, titled whatever the value is in Me.DepNameBox, as a PDF to a specific directory?



Thanks
 
Last edited:

Ranman256

Well-known member
Local time
Today, 19:36
Joined
Apr 9, 2015
Messages
4,339
Don't put the where in code, put it in the query,...
Select * from table where dept = forms!myForm!cboDept

Then just output the query.
 

June7

AWF VIP
Local time
Today, 15:36
Joined
Mar 9, 2014
Messages
5,423
Once the report is open, use OutputTo method.

Your filter criteria will probably work, I've just never structured filter like that. Alternative filter structure:

Code:
DoCmd.OpenReport Me.RepNameBox, acViewReport, , IIf(Me.DepNameBox = "All", "", "dept='" & Me.DepNameBox & "'")
DoCmd.OutputTo acOutputReport, , acFormatPDF, "filepath\" & Me.DepNameBox & ".pdf"
 
Last edited:

xyba

Registered User.
Local time
Today, 23:36
Joined
Jan 28, 2016
Messages
189
Once the report is open, use OutputTo method.

Your filter criteria will probably work, I've just never structured filter like that. Alternative filter structure:

Code:
DoCmd.OpenReport Me.RepNameBox, acViewReport, , IIf(Me.DepNameBox = "All", "", "dept='" & Me.DepNameBox & "'")
DoCmd.OutputTo acOutputReport, , acFormatPDF, "filepath\" & Me.DepNameBox & ".pdf"

Works perfectly. Thank you.
 

Users who are viewing this thread

Top Bottom