Print Preview question

T

terry w

Form frmParts has a command button used to print reports. The button's click
event has code DoCmd.OpenReport strRptName, acViewPreview

Often I don't print the report, but just examine it. Then I'll get a new
value from the form's combbox and click the command button to preview the
same report but with different date ranges, etc.

My question is this - I always have to manually close the 1st Preview
window before opening the 2nd. I need the command button, in English, to do
this: if the report I'm trying to preview already has an earlier preview
version open, then close it before opening the new preview. What is a good
way to do this?
 
A

Allen Browne

In essence, you just examine the IsLoaded property of the report in the
AllReports() collection, and close it if it is open.

It's worth creating a little function that does this, and solves some other
issues as well. If the report takes long to open, the user may cancel it,
triggering error 2501. You also get that error if the report's NoData event
cancels it. It makes sense to write a function that handles the errors, and
returns True if the report opened.

There's an example of such a function here:
http://allenbrowne.com/AppPrintMgtCode.html#OpenTheReport

Delete the block between:
'Set the printer for this report (if custom property defined).
and:
'Open the report

The WindowMode and OpenArgs part work only in Access 2002 or later.
 
T

terry w

Allen - there's a lot to chew on in your function example. Thanks for the
great reference.
 

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