Cancel a custom parameter form

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
 
R

Rob Parker

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
 

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