Form_open Cancel question

  • Thread starter Thread starter Mr. T.
  • Start date Start date
M

Mr. T.

Hi,

i've got a form where i'm calling another form with Docmd.Openform

now in the form i'm calling, in the form_open, i'm testing a few conditions.
Only if the conditions are met the form should open. so when the conditions
aren't met i say

Cancel = True

But then in the calling form i get an error, saying that opening the other
form was cancelled. Which is logical, since i cancelled it. However, i don't
want that error, i just want te form not to open if those conditions aren't
met.

Any ideas on this?

Thx in advance!

Thomas L.
 
Add error-handling to the procedure that contains the OpenForm.
Trap and ignore error 2501.

Example:

Private Sub OpenMyFOrm_Click()
On Error GoTo Err_Handler

DoCmdOpenForm "Form2"

Exit_Hander:
Exit Sub

Err_Handler:
If Err.Number <> 2501 Then
MsgBox "Error " & Err.Number & ": " & Err.Description
End If
End Sub

More on error handling:
http://allenbrowne.com/ser-23a.html
 
Back
Top