CancelEvent problem

jenntheblond

Registered User.
Local time
Today, 15:20
Joined
May 9, 2001
Messages
15
I have a bunch of forms that when opened they each pop up a dialog box which requests report info. I want the user to be able to cancel (via a command button) if they wish. When I pull up the report from the database window, this works perfectly.
HOWEVER, when I try to do this via a centralized "report form" that I have made, the CancelEvent doesn't work.
Process goes like this:
Click a button on the "Report Central" form which opens the report. (docmd.open form)
OnOpen of report opens a dialog form.
Dialog form has some combo boxes and such for choosing, and then a CANCEL and a GO button.
When I hit cancel, i set a boolean variable called varcontinue to false and close the dialog box.
At this point, in the OnOpen event of the Report, i have this code:
If varcontinue = false then
docmd.cancelevent
exit sub
End If

For some reason, this doesn't work unless form is opened directly from the window. What can I do here? docmd.Setwarnings doesn't help because this problem is a run-time error (Error 2501: The OpenReport Action was Cancelled). Well, i KNOW the Openreport action was canceled, that was my intent! How can i solve this annoyance?
THanks!
 
OK that sounds great, but where do i put this code? i've never had to do anything like this before, so please go slow!
 
Rich,

Because the error is a run time, I don't seem to be able to trap it via the way you suggest (the err.number is 0), and subsequently still get the problem Jenn had.

Any other thoughts on how to get rid of this?

Cheers,

Code:
On Error GoTo RptErr

DoCmd.OpenReport "RptZeroTransactions", acViewPreview

DoCmd.Maximize

 DoCmd.CancelEvent
        Cancel = True
        
RptErr:
        If err = 2501 Then
Exit Sub
        End If
End Sub
 
Mark Wild said:
Code:
On Error GoTo RptErr

DoCmd.OpenReport "RptZeroTransactions", acViewPreview

DoCmd.Maximize

         
RptErr:
        If err = 2501 Then
Exit Sub
        End If
End Sub



What's this for

DoCmd.CancelEvent
Cancel = True ???
 
It's how I thought i should be shutting down the rpt that has no data (from examples on the forum).

The RptZeroTransactions is not the report that has no data, but is printed for audit purpose
 

Users who are viewing this thread

Back
Top Bottom