how can i cancel a report from previewing?

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
 
W

Wayne Morgan

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
 
J

James

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
 
Top