Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error handler in one form catching error on another form

Status
Not open for further replies.

BrianB

Programmer
Oct 2, 2000
186
US
Hi folks, I have two forms, one of which calls a sub located in another.
My error handler on form1 does not seem to be handling errors that occur in the sub it called on form2.


Form1 code:
Private Sub Command1_Click()
On error goto Err_Command1_Click

Form2.Show
call Form2.GetRecord
Exit Sub
Exit_Command1_Click:
Exit Sub

Err_Command1_Click:
'clever code that logs the error
Msgbox "the following error occurred: " & err.description
Resume Exit_Command1_Click
End Sub


Form2Code:


Public Sub GetRecord
On error goto Err_GetRecord


'Many database operations here


Exit Sub

Err_GetRecord:
err.raise err.number,"form2_GetRecord",err.description

End Sub


The trouble is, that the err.raise statement doesn't send the error to the calling code on form1, it just throws a runtime error. Is this by design? Can error handlers defined on one form not catch errors occuring on another?
 
You have two options:

Remove the error handling code from the second form (then the error will automatically be propagated back to the first form).

or

In the error handling routine in the second form, save the details of the error into local variables and then re-raise the error.


Madlarry
 
Thanks for the quick reply!

save the details of the error into local variables and then re-raise the error.


You mean like this?

dim lngNum as Long
dim strDesc as string
dim strSource as string

lngNum = err.number
strDesc = err.description
strSource = err.source

err.raise lngnum,strsource,strdesc

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top