How to filter a report object when saving through FileDialog in MS Access

I am trying to save an rtf file using FileDialog and would like to filter using the 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 on how I can add a where clause without changing the report?

+3
source share
1 answer

I found that the easiest way to do this without touching the report code itself is to open the report in preview mode by applying a filter, and then display the report in any 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
+3
source

Source: https://habr.com/ru/post/1697732/


All Articles