Form.open - Cancel without Error Message

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
 
F

Fredg

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
 

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