Cancel a custom parameter form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am running a report from a command button which first opens up a custom
parameter form. (ref:
http://office.microsoft.com/en-us/assistance/HA011170771033.aspx). Everything
works fine except when I click Cancel on the parameter form it errors. The
code behind the Cancel button is DoCmd.Close.

The error is:Run-time error '2501':
The OpenReport action was cancelled.

How do I avoid this and just return to the first form?

Thanks in advance
 
The simplest wayis to add the following to cope with the error:

On Error Resume Next

This should be placed immediately before the code which opens your form, eg:

On Error Resume Next
DoCmd.OpenForm "frmMyParameterForm" ....

If you have other error trapping in your calling form, you can use the
returned error code to deal specifically with the Cancel error code, by
using code such as:

Err_cmdOpenForm_Click:
If Err.Number = 2501 Then
Resume Next
Else
... 'existing error trap code
End If

HTH,

Rob
 
Back
Top