PDA

Click to See Complete Forum and Search --> : error Handling


Leeper77
Jan 27th, 2000, 10:50 PM
I have a general question i want to create some error handling but dont know how to go about doing it.... My greatest concern for error handling is that when a person deletes some information from a database and theres nothing to delete i get an error and thats the one id like to handle...

Do You have any ideas?

thanks

VBfreak
Jan 28th, 2000, 11:07 AM
You have to set an Error handling branch at the first of your procedure. The first statement should read something like that

On Error GoTo ErrHandler <--- Call it whatever you want

Delete your record or whatever....

Exit Sub

ErrHandler: <--- Notice the same name!

If (Err.Number = [Whatever Error number you get]) then

Do some stuff.. like a message box!
End If

End Sub

You can go endlessly checking the Error number for different errors and then handling them properly! Notice that there is an "Exit Sub" and then an "End Sub" after the Error handler. That is because if there is no error the code will not branch to the error handler but it will run through and execute all the IFs in the error handler even if there is no error and you don't need that to execute if there is no error. The Exit Sub prevents from executing useless code!

Hope this can help my friend!

[This message has been edited by VBfreak (edited 01-28-2000).]