Use one report with two queries

P

Peter

I have a complicated report the gets its data from a query, it works
well. I now wish the use a copy of my report with a different query, ie
with a different Control source. I know I can specify the query or
Table to be used in my report when it is first set up but how do I
change the query to be used for a report without designing a new, but
identical, report?
 
R

Roger Converse

Hello,

All you need to do to copy a report is right click on the report, click
copy, right click again (not on an existingreport) and click paste. You
should be prompted as to what you want to call this new report.

Once the report is copied, you can go into the properties of the new report
and switch out the queries. Now, you'll want to make sure you pay attention
to the field names. If those are not the same between the queries, you will
want to address that (i.e. query1 field = DOB & query2 field = BirthDate).

HTH,
Roger
 
G

George Nicholson

You can certainly swap out different queries as Recordsources for a single
report.
Of course, the queries have to contain the same field names, etc., or the
results will be ugly (if there are results).

One approach:

1) When you open the report, pass the name of the query you want to use via
the OpenArgs argument of the OpenReport method:
If chkBox1 then
DoCmd.OpenReport "MyReport",,,,,"qryOneName"
End if

If chkBox2 then
DoCmd.OpenReport "MyReport",,,,,"qryTwoName"
End if

Then, in the Open event of the Report
Me.Recordsource = Me.OpenArgs

If you want to change any labels you can do that in the Open event as well:

Select Case Me.OpenArgs
Case "qryOneName"
me.lblReportHeader.Caption = "Query One Report"
Case "qryTwoName"
me.lblReportHeader.Caption = "Query Two Report"
Case Else
'Do Nothing
End Select

As I recall, OpenArgs for *reports* was not available in Access 97 and
earlier. I'm not 100% sure when it was added, certainly by 2002/XP, but I'm
at all sure about its availability in 2000.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top