Form.open - Cancel without Error Message

  • Thread starter Thread starter Mike Thomas
  • Start date Start date
M

Mike Thomas

In the open event of a form I have the code:

IF somecondition = true then
cancel = true
end if

This works, the form is closed, but it generates the error:

"The OpenForm action was cancelled"

Pressing the Debug button puts me on the line which opened the form:

DoCmd.OpenForm "Order", acNormal, , , , acWindowNormal

How can I turn the error message off?

Many thanks
Mike Thomas
 
You have to trap the error.

On Error GoTo Err_Handler
IF somecondition = true then
cancel = true
end If

Exit_This_Sub:
Exit Sub
Err_Handler:
If Err = 2501 Then
Else
MsgBox "Error " & Err.Number
End If
Resume Exit_This_Sub
 
Back
Top