|
-
Jul 12th, 2000, 03:40 PM
#1
Thread Starter
Hyperactive Member
I have sub2 in a module that is called from sub1 in another module. sub1 has error trapping, and sub2 has none; however during execution sub2 should have some errors but never cause an error. Implementing 'On Error GoTo 0' has no effect.
Can someone explain what's going on and how I can recieve error messages?
-
Jul 12th, 2000, 04:36 PM
#2
Not quite sure what you are on about
-
Jul 12th, 2000, 05:11 PM
#3
Jethro: On Error GoTo 0 turns off error chacking in a sub or function:
Phobic: Change Sub2 to a function (which I have called FunctionWithError) and do something like the following:
Code:
Option Explicit
Private Sub Form_Load()
Sub1
End Sub
Public Function FunctionWithError() As Long
On Error Resume Next
' Code that causes an error
Dim x As Integer
x = 6 / 0
FunctionWithError = Err.Number
End Function
Public Sub Sub1()
On Error GoTo ErrorRoutine
Err.Raise FunctionWithError
Exit Sub
ErrorRoutine:
If Err.Number <> 0 Then
MsgBox "FunctionWithError returned err number " & Err.Number
End If
End Sub
-
Jul 12th, 2000, 05:22 PM
#4
Thread Starter
Hyperactive Member
This is kidna waht I'm looking for, except it won't work for these cases. Sub2 has multiple errors, and they are the same type of errors in Sub1 but need to be handled differently. Any suggestions?
-
Jul 12th, 2000, 06:11 PM
#5
Try Calling your Sub before your On Error Resume Next statement.
Code:
Sub Sub1()
Call Sub2
On Error Resume Next
'Raise Error 6
Err.Raise (6)
Form1.Print "Sub2"
End Sub
Sub Sub2()
On Error GoTo 0
'Raise Error 6
Err.Raise (6)
Form1.Print "Sub1"
End Sub
Private Sub Form_Load()
'Call Sub1 when the Form loads.
'We should get an overflow Error.
Call Sub1
End Sub
-
Jul 12th, 2000, 06:41 PM
#6
Still confused here
Martin
Thanks man l didn't know that
Megatron
What are we trying to achieve? Does he want the errors reported in Sub2 or is he trying to not report them???
If not wanting them reported something like
Code:
On Error Resume Next
Err = 0
I am just confused by the problem definition???
Phobic
Could you explain it a bit more or has one of the gurus answered your problem????????
-
Jul 12th, 2000, 06:49 PM
#7
however during execution sub2 should have some errors but never cause an error. Implementing 'On Error GoTo 0'
As I understood it, Jethro, he wants to have Error's in Sub2.
-
Jul 12th, 2000, 07:53 PM
#8
Thanks Megatron
For sure On Error Resume Next is causing the problem, can out the line of code...unless there is an
error you expect and can recover from.
-
Jul 13th, 2000, 09:30 AM
#9
Thread Starter
Hyperactive Member
Blarg, I can't do that either. The code runs something liked this (another high quality example):
Code:
On Error GoTo errs
Do
If Code Then
Code 'Causes a trappable error in errs
Else
Code 'Also Causes a trappable error
Call Sub2() 'Second Sub MUST be called here, it's getting more information from previous code just delt with.
End If
Loop Until Conditions Met
Exit Sub
errs:
FixIt
Resume
As you can see, I need all the code as it is, and both subs have the same type of errors, but need dealt with differently. This is why I want to be able to do error trapping in the second sub, but why can't I?
-
Jul 13th, 2000, 06:44 PM
#10
Hmmmm.......
Ok do you have an On Error statement in Sub2?
If so ensure it's not that GoTo 0 thing that Martin pointed out, and there is no Resume Next modifier, ok that should trap your error in the Sub
Code:
Sub Start or whatever
On Error GoTo Sub2Err
'
'
' code, code, code
'
Exit Sub
Sub2Err:
MsgBox "Oh my God the world is about to Explode"
Fixit or crash out
End Sub
Hope that helps or at least provides food for thought
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|