none
Error trapping in a case module... RRS feed

  • Question

  • I'm using a Visio case module (but it can be any MS app).  When I get an error in my case module how can I pass the error number back to my main sub procedure?

    Many thanks 

    James


    Andrew Binnz

    Thursday, June 25, 2015 12:57 AM

Answers

  • simple cases

    Sub Test()
    On Error GoTo blad
    Dim t%: t = 4 ' try with "a"
        Select Case t
            Case Is = 1:
            Case Is > 6:
            Case Else: MsgBox "Another value then case expected"
        End Select
    
    Exit Sub
    blad:
    MsgBox Err.Number & " " & Err.Description, , "Err from inside cases sub"
    End Sub

    sub procedure

    Sub Test()
    On Error GoTo blad
    Dim t As Variant: t = "a"
    Call bbb(t)
    
    Exit Sub
    blad:
    MsgBox Err.Number & " " & Err.Description, , "Err from sub bbb"
    End Sub
    
    Sub bbb(l As Variant)
    Debug.Print l * 45
    End Sub



    Oskar Shon, Office System MVP - www.VBATools.pl
    if Helpful; Answer when a problem solved

    Thursday, June 25, 2015 9:22 AM
    Answerer

All replies

  •  This question also posted in the Excel for Developers forum.
    Thursday, June 25, 2015 3:11 AM
  • simple cases

    Sub Test()
    On Error GoTo blad
    Dim t%: t = 4 ' try with "a"
        Select Case t
            Case Is = 1:
            Case Is > 6:
            Case Else: MsgBox "Another value then case expected"
        End Select
    
    Exit Sub
    blad:
    MsgBox Err.Number & " " & Err.Description, , "Err from inside cases sub"
    End Sub

    sub procedure

    Sub Test()
    On Error GoTo blad
    Dim t As Variant: t = "a"
    Call bbb(t)
    
    Exit Sub
    blad:
    MsgBox Err.Number & " " & Err.Description, , "Err from sub bbb"
    End Sub
    
    Sub bbb(l As Variant)
    Debug.Print l * 45
    End Sub



    Oskar Shon, Office System MVP - www.VBATools.pl
    if Helpful; Answer when a problem solved

    Thursday, June 25, 2015 9:22 AM
    Answerer
  • Thanks Oskar but I think there has been some confusion.  What I want to know is if there is a way to capture an error message in a sub procedure in a case module (this is not using a select case statement).  

    My case module has lets and gets to capture variable from my sub procedure.  I then have a case sub procedure inside the case module.  However if there is an error here, can I pass the error msg back to my sub procedure?

    Hope this makes sense.

    Many thanks 

    James 


    Andrew Binnz

    Tuesday, July 7, 2015 8:21 AM
  • Paste sample pls.

    Sandard error command is:

    On Error GoTo Jump_Name

    'some code

    exit sub

    jump_name:

    'whatever you want (show, save or not, error destription for example)

    exit sub

    You can also use public string variables , for errors too. Then check len() of variable to show or not any errors from any procedures you call.


    Oskar Shon, Office System MVP - www.VBATools.pl
    if Helpful; Answer when a problem solved

    Tuesday, July 7, 2015 1:07 PM
    Answerer