You apparently do not have any structured error handling in your code. A compile error will be flagged by the compiler, but a runtime error will not. If you have SubA that calls SubB, and SubB has a runtime error that is not handled, then it will bubble up to SubA and you may think that SubA was the cause of the error. Without any error handling, the best you can narrow it down to in troubleshooting, is that the problem was in the last command you ran. Below is a function that I've added error handling to. If an error occurs, code execution is routed to Err_Control. Here the error code is tested against possible known errors using a Select..Case statement. If a Case tests true, you can handle the error, reset the error object and resume at Exit_Here or some other point in the sub. If none of the errors test true, execution flows to the Case..Else statement, which just reports the error and the dialog title gives you the function that errored. Then you can set a breakpoint in the function/sub and continue debugging.
Public Function XYZDistance(Point1 As Variant, Point2 As Variant) As Double
On Error GoTo Err_Control
'Returns the distance between two points
Dim dblDist As Double
Dim dblXSl As Double
Dim dblYSl As Double
Dim dblZSl As Double
Dim varErr As Variant
On Error GoTo Err_Control
'Calc distance
dblXSl = (Point1(0) - Point2(0)) ^ 2
dblYSl = (Point1(1) - Point2(1)) ^ 2
dblZSl = (Point1(2) - Point2(2)) ^ 2
dblDist = Sqr(dblXSl + dblYSl + dblZSl)
'Return Distance
XYZDistance = dblDist
Exit_Here:
Exit Function
Err_Control:
Select Case Err.Number
'Add your Case selections here
'Case Is = 1000
'Handle error
'Err.Clear
'Resume Exit_Here
Case Else
MsgBox Err.Number & ", " & Err.Description, , "XYZDistance"
Err.Clear
Resume Exit_Here
End Select
End Function
Ed
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to
post your code.![EESignature EESignature](http://autodesk.i.lithium.com/t5/image/serverpage/image-id/1272565i464DC3DC646B4F11/image-size/original)