PDA

View Full Version : Adding a filter to reports



Kicker
10-12-2017, 01:46 PM
Here is an interesting one for you guys. On a form, I have two command buttons. Both of them call the same report. One of them displays the report and one of them outputs the report to a pdf file. However, the method of calling the report differs.

This command opens the report perfectly on the screen. a_Season(x,y) provides a 'start' and an 'end' date range.

Private Sub cmdClassSchedule_Click()
DoCmd.OpenReport "rpt_Class_Schedule", acViewReport, , _
"(left([Class_Type_Code],3) = 'GVR') AND [Date_1] >= #" & a_Season(1, 2) & _
"# AND [Date_1] <= #" & a_Season(1, 3) & "#"
End Sub

This command outputs the report to the appropriate pdf file.

Private Sub cmdCreatePDF_Click()
Dim strPath As String
strPath = CurrentProject.Path
DoCmd.OutputTo acOutputReport, "rpt_Class_Schedule", "PDF Format", strPath & "\Class_Schedule.pdf"
End Sub


My issues is that I need to send the file to a pdf file but the DoCmd.OutputTo command doesn't all for the filter.

I don't want to have to create two identical reports with different queries.

any ideas?

OBP
10-13-2017, 07:55 AM
There are a few methods to do this
a. Hard code the Filter in the Report. (Easy)
b. Hard code the filter in the Report's underlying Query. (Easy)
c. Program the Query from the Form. (Fairly easy)
d. Create the Query for the Report using the QueryDef. (Harder)
e. Create an SQL and assign to the report using VBA. (Also Harder).

Kicker
10-13-2017, 09:37 AM
OBP. Yeah, I was kinda thinking the same thing.

There are a few methods to do this
a. Hard code the Filter in the Report. (Easy). I only want the report to select a specific range of dates within the entire table so I need to send those dates when the report is printed.
b. Hard code the filter in the Report's underlying Query. (Easy).This won't allow me to control the dates very easily
c. Program the Query from the Form. (Fairly easy).. I was thinking about this. If I use some public date variables and set them with VBA, that might work. But, I am calling the reports from many directions and that might get confusing. But this looks like the best option
d. Create the Query for the Report using the QueryDef. (Harder)
e. Create an SQL and assign to the report using VBA. (Also Harder).

thank you for your ideas. I will let you know the solution once written


http://www.vbaexpress.com/forum/images/reputation/reputation_pos.pngJoinedMar 2005Posts2,592Locationhttp://www.vbaexpress.com/forum/images/flags/United%20Kingdom%203D.gif http://www.vbaexpress.com/forum/images/flags/provinces/Wales%203D.gif


There are a few methods to do this
a. Hard code the Filter in the Report. (Easy)
b. Hard code the filter in the Report's underlying Query. (Easy)
c. Program the Query from the Form. (Fairly easy)
d. Create the Query for the Report using the QueryDef. (Harder)
e. Create an SQL and assign to the report using VBA. (Also Harder)

OBP
10-13-2017, 09:42 AM
Let me know if you need any help.