Do nothing when cancel is clicked

  • Thread starter Thread starter Perry Kew
  • Start date Start date
P

Perry Kew

I have the following code attached to a button in a form.
It opens the report when all goes well. When cancel is
clicked it gives me the error message below. I was
wondering if someone could tell me what I can do to make
it such that when the Cancel button is clicked, it just
goes back to the form and does not display the message
box.

Thanks for your help.


On Error GoTo Err_cmdClosedBy_Click

DoCmd.OpenReport "rptBooksMags", acViewPreview
DoCmd.Maximize

Exit_cmdClosedBy_Click:
Exit Sub

Err_cmdClosedBy_Click:
MsgBox "The BooksMag Report has been cancelled"
Resume Exit_cmdClosedBy_Click
 
Perry Kew said:
I have the following code attached to a button in a form.
It opens the report when all goes well. When cancel is
clicked it gives me the error message below. I was
wondering if someone could tell me what I can do to make
it such that when the Cancel button is clicked, it just
goes back to the form and does not display the message
box.

Thanks for your help.


On Error GoTo Err_cmdClosedBy_Click

DoCmd.OpenReport "rptBooksMags", acViewPreview
DoCmd.Maximize

Exit_cmdClosedBy_Click:
Exit Sub

Err_cmdClosedBy_Click:
MsgBox "The BooksMag Report has been cancelled"
Resume Exit_cmdClosedBy_Click

I guess Cancel would be clicked on a parameter prompt, or some dialog in
the form's Open event that cancels the report? To ignore a "cancel"
action while still reporting other errors that may occur, change the
last few lines like this:

'----- start of replacement code -----
Err_cmdClosedBy_Click:
If Err.Number <> 2501 Then
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
End If
Resume Exit_cmdClosedBy_Click
'----- end of replacement code -----
 
Back
Top