how can i cancel a report from previewing?

  • Thread starter Thread starter James
  • Start date Start date
J

James

how can i cancel a report from previewing? when my report opens, it runs a
form. if i close that form i want it to cancel the report
 
I'm assuming you're opening the form in the Open event of the report. If so,
are you using the acDialog window mode argument in the DoCmd.OpenForm call?
This argument will open the form as a popup and pause the code in the
report's Open event until you close or hide the form. If you hide the form,
then you want to continue (don't forget to close it later, such as when you
close the report), if you close the form you want to cancel.

In the line of code after the OpenForm command, check to see if the form is
still open. If it isn't, then Cancel the report's Open event. You do this by
setting Cancel = True. If the report was opened by code, this will cause the
code that opened the report to generate a 2501 error. Just trap the error
and ignore it.

To see if the form is open, see this code example:
http://www.mvps.org/access/forms/frm0002.htm
 
Thank You! works perfectly!


Wayne Morgan said:
I'm assuming you're opening the form in the Open event of the report. If
so, are you using the acDialog window mode argument in the DoCmd.OpenForm
call? This argument will open the form as a popup and pause the code in
the report's Open event until you close or hide the form. If you hide the
form, then you want to continue (don't forget to close it later, such as
when you close the report), if you close the form you want to cancel.

In the line of code after the OpenForm command, check to see if the form
is still open. If it isn't, then Cancel the report's Open event. You do
this by setting Cancel = True. If the report was opened by code, this will
cause the code that opened the report to generate a 2501 error. Just trap
the error and ignore it.

To see if the form is open, see this code example:
http://www.mvps.org/access/forms/frm0002.htm
 

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

Similar Threads


Back
Top