Every time there is an error, I like my program run another procedure and when it finish, go to the next line in the original procedure.
Do I use "On error Goto"? Please give me an example because I am stuck.
Printable View
Every time there is an error, I like my program run another procedure and when it finish, go to the next line in the original procedure.
Do I use "On error Goto"? Please give me an example because I am stuck.
Yes here's the basic idea about error handling:
On error goto errorhandler:
a statement or method causing error
exit [methodtype] 'avoids errorhandler to execute after method contents
errorhandler:
handling the error
resume next 'Resumes to next line
All you need is the Resume Next in you Error Handle routine to continue the next command line.
Code:Private Sub Form_load()
On Error Goto MyErrorHandle
>>Your code here
Exit Sub
MyErrorHandle:
>>Do What ever you want here.
Resume Next
End Sub
Thanks in a million to both of you guys.
Thanks for the detail code Chris!
Bye
:):):):):):):):):):):):):):):):):):):):):):):):):):)
Hello Shark!
You should take a look at these too.
- Resume
- Resume [0]
- Resume Next
- Resume line
Ok if you are expecting an error...you probably know the line of code that is going to generate it...(does happen and can be valid e.g testing for an Excel instance). Trap the error with something like
If Err = 427 Then Err = 0
Allows the program to continue execution without any GoTos.
Probably not what you are after but what the heck its FYI