INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

VBA Visual Basic for Applications (Microsoft) FAQ

VBA How To

A simple error handling technique for VB/VBA apps by taupirho
Posted: 29 Jun 04 (Edited 19 May 05)

You should include error handling in all your VB or VBA code. Here's a simple but effective way to do so.

Private Sub CommandButton_Click()

On Error GoTo err_handler

'All your main code goes below
'

...
...


' Now the error handling bit

endit:
Exit Sub

err_handler:
MsgBox _
"An unexpected error has been detected" & Chr(13) & _
"Description is: " & Err.Number & ", " & Err.Description & Chr(13) & _
"Module is: commandbutton_click" & Chr(13) & _
"Please note the above details before contacting support"
Resume endit

End Sub

One of the good things about doing it this way is that the error handling code is the same for every module with the exception of the Module is: part of the msgbox statement. It's simply a matter of cutting and pasting the code to your other modules. Easy and effective.


Back to VBA Visual Basic for Applications (Microsoft) FAQ Index
Back to VBA Visual Basic for Applications (Microsoft) Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close