How to filter a report object when saving through FileDialog in MS Access
-
03-07-2019 - |
Question
I am attempting to save an rtf file using FileDialog and would like to filter using a where clause. This is what I have:
Set dlgSave = FileDialog(msoFileDialogSaveAs)
With dlgSave
.Title = "Provide the place to save this file"
.ButtonName = "Save As..."
.InitialFileName = Me.cmbPickAReportToPrint.Value & "-" & Format(Date, "mmddyy") & ".rtf"
.InitialView = msoFileDialogViewDetails
If .Show Then
DoCmd.OutputTo acOutputReport, Me.cmbPickAReportToPrint.Value, acFormatRTF, .SelectedItems(1)
End If
End With
Any ideas as to how I could add the where clause without otherwise changing the report?
Solution
I've found that the easiest way to do this without touching the report code itself is to open the report in preview mode with the filter applied, and then output the report to whatever format you need.
If .Show Then
DoCmd.OpenReport Me.cmbPickAReportToPrint.Value, acViewPreview, , "fieldToFilterOn = 'value'"
DoCmd.OutputTo acOutputReport, Me.cmbPickAReportToPrint.Value, acFormatRTF, .SelectedItems(1)
End If
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow