Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 147
Default On Error Command

Hi all,

I was wondering if there was a way to do some sought of global On Error
Command because all I need is for it to pop up with the same message and to
go throughout all of my forms & modules and put on the On Error Command and
with the Error Trapping in all of my proceedures?

Jason
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default On Error Command

Jason,
There no simple "On Error Call ThisRoutine" that you can use in VBA.
But if the top most (first) routine has an error handler active, with the
"On Error GoTo [Handler]" syntax, errors will bubble up to from called
routines, if they do not deal with the error themselves.
You can see what happens if you comment out the line
On Error GoTo CommandButton1_Error

If you need error handling added to all your routines, I believe MZTools
provides a simple way of this.
http://www.mztools.com/index.htm

Private Sub CommandButton1_Click()
On Error GoTo CommandButton1_Error

Call FunctionWithHandler
Call FunctionWithOutHandler
'Call AnyOtherRoutine

Exit Function
CommandButton1_Error:
Select Case Err.Number
Case vbObjectError + 514
MsgBox "Error from " & Err.Source
Resume Next
Case vbObjectError + 515
MsgBox "Error from " & Err.Source
Case Else
MsgBox "Error from " & Err.Source
End Select
End Sub

Private Function FunctionWithHandler() As Long
On Error GoTo FunctionWithHandler_Error
'Force an error
Err.Raise vbObjectError + 513, "FunctionWithHandler", "Handled in this
routine"
'Force an error
Err.Raise vbObjectError + 514, "FunctionWithHandler", "Not handled in this
routine"

FunctionWithHandler = 1

Exit Function
FunctionWithHandler_Error:
Select Case Err.Number
Case vbObjectError + 513
'Handle the error somehow
Resume Next
Case Else
'Pass the error up to the next active error handler
Err.Raise vbObjectError + 514, "FunctionWithHandler", "Not handled in
this routine"
End Select
End Function

Private Function FunctionWithOutHandler() As Long
'Force an error
Err.Raise vbObjectError + 515, "FunctionWithOutHandler", "Not handled in
this routine"
FunctionWithOutHandler = 1
End Function

NickHK

"Jason Zischke" wrote in message
...
Hi all,

I was wondering if there was a way to do some sought of global On Error
Command because all I need is for it to pop up with the same message and

to
go throughout all of my forms & modules and put on the On Error Command

and
with the Error Trapping in all of my proceedures?

Jason



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error when using Sum command ALAMATAHA Excel Discussion (Misc queries) 3 January 26th 10 05:33 PM
Pivot Table Error Message - "Command Text not set for command obje Jeff Divian Excel Discussion (Misc queries) 0 November 7th 07 10:26 PM
Error with Goto command excelnut1954 Excel Programming 3 October 13th 06 02:48 PM
Do loop error while using FindNext command Adam Excel Programming 0 June 29th 06 06:44 PM
Why does the error pop up- can't enter command mode? Thief_ Excel Programming 0 April 7th 05 06:43 AM


All times are GMT +1. The time now is 06:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"