Would my code go something like this?
DoCmd.OpenReport "rptCatalog"
If OptionA =1 Then
Reports!rptCatalog.RecordSource = "MyQuery"
End If
If OptionA =2 Then
Reports!rptCatalog.RecordSource = "MyQuery1"
End If
No it would not go like that.
What are the differences between the queries?
Only the criteria or do they each return different fields.
If they each return different fields, then you would be probably be
better off to have 3 different reports.
If the fields are the same in all three, but the criteria fields are
different, you could open the one report using the filter argument of
the OpenReport method.
Assuming you have 3 different queries:
Dim strQuery as String
If OptionA = 1 Then
strQuery = "Query1"
Elseif OptionA = 2 Then
strQuery = "Query2"
Else
strQuery = "Query3"
End if
DoCmd.OpenReport "ReportName", acViewPreview, strQuery
The above Filter argument is seldom used.
Better yet, simply have one report that returns all the records (no
criteria), and use the Where clause argument, instead of the filter
argument, to open the correctly filtered report.
Dim strWhere as string
If OptionA = 1 Then
strWhere = "[RecordID] = " & Me![RecordID]
ElseIf OptionA = 2 Then
strWhere = "[CompanyName] = """ & Me![CompanyName] & """"
Else
strWhere = "[SalesDate] = #" & Me![SalesDate] & "#"
End If
DoCmd.OpenReport "ReportName", acViewPreview, , strWhere
Note that there is a difference in the syntax when writing a where
clause depending upon the criteria field's datatype.
In order above, Number, Text, and Date datatypes.
In VBA help, look up OpenReport, Where clause, and Restrict data to a
subset of records, for more information.