Error Handler screwing up

agehoops

Registered User.
Local time
Today, 16:33
Joined
Feb 11, 2006
Messages
351
I've got an error handler to obviously check for and error, however it is saying there's an error when there isn't one.

I've got one very large IF statement running with others in it. Outside the if statement is the error command to go to the function of what to do on an error, which is outside the IF statement at the end.

When I run the code, if there is an error, it works as should, however even when there isn't an error it is running (I removed it, and tested without it and it ran perfectly)

Any ideas as to why it's doing this?

Thanks
 
check if you have enough Exit subs.
Code:
On Error Goto Err_Procedure

Exit_Procedure:
' Forgot Exit sub statement
Err_Procedure
   Errorproc Err, Err.description
End Sub
This gives you an error message when there isn't one.
 
Last edited:
I assume you've put something like an
Err_Exit:
Exit Sub
at the end of your main code and before the error handling code so that it doesn't just drop into it every time?
 
at the very beginning of the code before anything else I have this

Code:
On Error GoTo Err:

Then at the end after everything I've got this

Code:
Err:
 MsgBox "There was a problem opening the Report" & vbNewLine & "Please try again", vbInformation, "There was a problem"
Exit Sub
 
What you should have is:
Err_Exit:
Exit Sub
Err:
MsgBox "There was a problem opening the Report" & vbNewLine & "Please try again", vbInformation, "There was a problem"
Exit Sub
You need to drop out before the error handler if everything's OK, otherwise you hit it every time!
 
ah perfect! Works a treat. Thanks very much. Never been that great with error handlers. Thanks again
 

Users who are viewing this thread

Back
Top Bottom