I'm struggling a little bit with handling the errors of a returning function in VBA.
I got some code in a sub which calls a function. The function returns 0 if it succeeds and -1 if there is an error.
This is my sub:
Sub mySub
Dim returnValue as Integer
returnValue = functionA(...)
If returnValue = -1 Then
MsgBox "The following error appeared: " & err.description & ", Errornumber= " & err.number
Else
MsgBox "Success"
End If
End Sub
My function looks like this:
Function functionA(...) as Integer
On error goto errorHandler
' do something
funtionA = 0
Exit Function
errorHandler:
functionA = -1
End Function
Now my problem: if the function returns -1 because it was stopped by an error, I cannot get any information from the error object in my calling sub. The errornumber is 0 and the description is emtpy. It seems like the end of the function resets the err object. Is there a smart way of achieving what I want to do?
Thanks in advance! :)
= err.description, so you can use your variable in yoru msgbox?