Open Report / Macro

  • Thread starter Thread starter t
  • Start date Start date
T

t

In MSAcess when using the OpenReport Macro, you can use
the "where condition" to create multiple reports with a
single report and query.

However, when attempting to output these reports with a
Macro, the OutputTo option does not include the "where
condition". This means I would have to have a separate
query and separate report for each condition I wish to
output.

Is there a simple solution to get around this limitation.
 
Yes. The simple solution is to read a global string variable in the Open
event procedure of the report, and filter it accordingly.

In the General Declarations section (at the top) of a standard module (one
on the Modules tab of the Database window), enter:
Dim gstrReportFilter As String

In the code that outputs the report, set the string, e.g.:
gstrReportFilter = "ClientID = 99"
DoCmd.OutputTo acOutputReport, "MyReport"

In the Open event procedure of the report:
Private Sub Report_Open(Cancel As Integer)
If Len(gstrReportFilter) > 0 Then
Me.Filter = gstrReportFilter
Me.FilterOn = True
gstrReportFilter = vbNullString
End If
End Sub
 
Back
Top