I'm trying to open and filter a report based on the report that a user selects from a combobox in a form. To simplify the example, here's what I'm dealing with:
First I'm opening the report:
Dim strReportName As String
strReportName = "General Information"
DoCmd.OpenReport strReportName, acViewPreview
This works fine, the problem arrises when I'm trying to apply a filter.
With Reports!strReportName
.Filter = strFilter
.FilterOn = True
End With
The problem I can't find my way around, is that it seems impossible to use a variable reportname in this syntax. Needless to say, the error thrown by VBA is as follows:
Run-time error '2451':
The report name 'strReportName' you entered is misspelled or refers to a report that
isn't open or doesn't exist.
My question is: Is there any way to alter this statement into letting me filter the report that's currently open without needing to hardcode the reportnames into VBA?