Results 1 to 10 of 10

Thread: Explanation

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263
    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?

  2. #2
    Guest

    Question Not quite sure what you are on about

    What do you mean by GoTo 0, is o a label???

    Ok put a new line of code at the top of Sub2

    Code:
    On Error GoTo Sub2ErrorMsg
    .
    .
    blah blah blah....great code, excellent result here
    .
    .
    Exit Sub
    .
    Sub2ErrorMsg:
    .
    Whatever
    .
    Would that sort of thing fix your problem? If not maybe slight more explanation of the problem.

    This posting should not be construed by John the admin as being helpful or providing support!!! Reason, have a look over in Forum Feedback


  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    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

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263
    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?

  5. #5
    Guest
    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

  6. #6
    Guest

    Unhappy 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????????

  7. #7
    Guest
    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.

  8. #8
    Guest

    Thumbs up 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.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263
    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?

  10. #10
    Guest

    Unhappy 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
  •  



Click Here to Expand Forum to Full Width