meboz
11-24-2004, 02:29 PM
Hi all,
I am opening a form via a button using the usual docmd.open "myform"
In the form_open event, I am making a function call, and in a given circumstance, a handled error occurs.
how do I set cancel = true when the error occurs in the called function?
Thanks in advance
ghudson
11-24-2004, 07:04 PM
Put this in the forms OnOpen event...
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Form_Open_Err
MsgBox "your code here"
Form_Open_Exit:
Exit Sub
Form_Open_Err:
If Err.Number = 12345 Then
DoCmd.CancelEvent
Else
MsgBox Err.Number & " - " & Err.Description
Resume Form_Open_Exit
End If
End Sub
You have to trap for the specific error number. I just used 12345 as an example.
meboz
11-24-2004, 08:29 PM
That makes sense ghudson.
The things is that the error is actually generated in a function that is called by the Form_open event, and that is the error number that needs to be in place of 12345
Any thoughts?
john471
11-25-2004, 02:18 AM
Meboz,
Are you saying that the error is both generated in and handled by the called function, thus the form_open event has no notification of the error ?
If that is the case, the called function needs to have a way of notifying the calling function that an error (or only the explicitly required error) occurred.
Perhaps if the error handler in the called function detects the explicit error, either have the function return an explicit (otherwise impossible) value, or have the error handler raise another error (err.raise), which would be passed back up the call stack to the open_form event, n'est pas ?
Regards
John
Mile-O
11-25-2004, 02:20 AM
What's the function that you are calling? Post the code.
ghudson
11-25-2004, 08:12 AM
You need to ensure that all of your Functions() and Subs() have error trapping. Then you can determine where you need to trap for a specific error.
Mile-O
11-25-2004, 08:59 AM
I'm going to suggest passing a boolean variable to the function (by reference) and, if there is an error, set it to True. If it comes back true you can manage your error handling in thecallin function.