Previewing a report revisited

J

Jim Pockmire

I have code that loops through some statements, previewing the same report
each time through. After the first report previews and I close it, the loop
seems to end and will not prewiew the remaining pages. If I insert a
Docmd.Close (report) in the loop, the report opens and closes without being
able to view it.

How can I preview the report, then wait for a user to press the "Close"
button on the report toolbar before progressing trough the loop and
displaying the next report?
 
R

Rick Brandt

Jim Pockmire said:
I have code that loops through some statements, previewing the same report
each time through. After the first report previews and I close it, the loop
seems to end and will not prewiew the remaining pages. If I insert a
Docmd.Close (report) in the loop, the report opens and closes without being
able to view it.

How can I preview the report, then wait for a user to press the "Close" button
on the report toolbar before progressing trough the loop and displaying the
next report?

You can't unless you do something to stop your code loop. If every report were
only one page and you didn't need to change the zoom level you could open the
form and then open a msgbox or a dialog form. That would pause your code loop
until that was closed. You wouldn't be able to interact with the report at all
though.

If this was the only way you wanted to view the reports you could drop the loop
and just have the close event of each report automatically open the next one.
 
J

Jim Pockmire

Each report is more than 1 page. I have tried to insert a msgbox at the on
close event, but this disrupts viewing the report. I can probably find a
work around if that is the only option.
 
J

John Spencer (MVP)

What version of Access?

I believe - can't test this here - that Access 2003 allows you to open a report
in dialog mode. In earlier versions, you could test whether or not the report
was open within a loop. If it was then you would execute a DoEvents and NOT
progress to the next report in the loop

UNTESTED CODE Snippet for Access 97 to Access 2003 - banged this together and it
is very probable that this is not the most efficient code

Public Sub sTest()
Dim rptAny As Report
Dim tfStillOpen As Boolean

'Start of Your Loop Code
DoCmd.OpenReport "rpt_WorkTimeSpent", acViewPreview

tfStillOpen = True
While tfStillOpen = True
tfStillOpen = False
For Each rptAny In CurrentDb().Reports
If rptAny.Name = "rpt_WorkTimeSpent" Then
tfStillOpen = True
DoEvents
Exit For
End If
Next rptAny
Wend
'End of your loop code

End Sub
 

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