Preview Multiple Reports

J

Jill Moffitt

I am generating the where clause for a report within a loop and then calling
DoCmd.OpenReport stDocName, acPreview, , strWhere

A preview pops up the first time then I don't get anything - if I step
through the process it will preview each report??

If I don't call acPreview all of the reports will pring (there's one per
year)

I've spoken with other access programers and no one seems to know a work
around but all have seen this behavior before

I am new to Access - and have been pulling my hair out for 2 days on this -
please HELP!!!

Thanks in advance =)
 
M

Marshall Barton

Jill said:
I am generating the where clause for a report within a loop and then calling
DoCmd.OpenReport stDocName, acPreview, , strWhere

A preview pops up the first time then I don't get anything - if I step
through the process it will preview each report??

If I don't call acPreview all of the reports will pring (there's one per
year)


OpenReport can not open a report that is already open.

What to Do?

Many times it's adequate to open the reports sequentially.
According to AXP Help, this can be managed by setting the
OpenReport method's WindowMode argument to acDialog. This
will pause the code until the report is closed, at which
time the code will resume and open the next report.

The other way to attack this issue is to create multiple
instances of the same report. (I suppose you could actually
make a dozen copies of the report and name them myreport1,
myreport2, etc, but that would be difficult to maintain and
is not the "object oriented" way to do things.)

Unfortunately, Access has some difficulty doing it the
"right" way, so you may not be able to get it to work
reliably. Anyway here's the general idea for you to play
around with.

First, as I said above, you can not use OpenReport so you
have to use Set New Report_nameofreport. This feature does
not provide for a strWhere argument so you have to provide
the entire recordsource SQL string (I've had trouble using
the report's Filter property).

Assuming you have a form with a command button to initiate
the reports and a hidden text box, txtSQL, on the form:

Dim rpts(99) As Report ' module level

Sub cmdPrint_Click()
Dim K As Integer
For K = 0 To N
strWhere = . . .
DoEvents 'give previous report time to catch up?
txtSQL = "SELECT . . . WHERE " strWhere
Set rpts(K) = NEW Report_nameofreport
rpt.Visible = True
Next
End Sub

Use code in the report's Open event to set its filtered
record source:

Me.RecordSource = Forms!MultiReportOpen.txtSQL
 

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