Error Handling

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Clive Moss

    Error Handling

    Hi all

    Am I missing something here?

    I have a number of procedures where error code like this works fine:
    Eg:
    Private Sub tglAllowEdit_Cl ick()
    On Error GoTo Err_tglAllowEdi t_Click

    If Me!tglAllowEdit = True Then
    Me!LockCode.Ena bled = True
    Else
    Me!LockCode.Ena bled = False
    End If

    Exit_tglAllowEd it_Click:
    Exit Sub

    Err_tglAllowEdi t_Click:
    MsgBox Err.Description
    Resume Exit_tglAllowEd it_Click

    End Sub

    For some others I get "Compile Error Label not defined"
    Example code:

    Private Sub Form_Current()
    On Error GoTo Err_Form_Curren t

    Me!LockCode.Ena bled = False

    Form_Current_Ex it:
    End Sub

    Err_Form_Curren t:
    MsgBox Err.Description
    Resume Form_Current_Ex it

    End Sub

    I can't see the difference - can anyone tell me what I'm doing wrong?

    TIA

    Clive


  • Mike Wiseley

    #2
    Re: Error Handling

    Simplify your error handling to use generic labels. You don't need labels
    with specific names that are different for each procedure. This might help
    reduce possible mistakes and confusion if you develop a lot of procedures. I
    would have done your first procedure as follows:

    Private Sub Form_Current()
    On Error GoTo Proc_Err

    Me!LockCode.Ena bled = False

    Proc_Exit:
    Exit Sub

    Proc_Err:
    MsgBox Err.Description
    Resume Proc_Exit

    End Sub

    Also, your second procedure has two End Sub statements (incorrect) , while
    the first procedure that you provided has an Exit Sub and an End Sub.

    "Clive Moss" <clive@REMOVEin stant-image.co.uk> wrote in message
    news:GfKcb.590$ pG.5096592@news-text.cableinet. net...[color=blue]
    > Hi all
    >
    > Am I missing something here?
    >
    > I have a number of procedures where error code like this works fine:
    > Eg:
    > Private Sub tglAllowEdit_Cl ick()
    > On Error GoTo Err_tglAllowEdi t_Click
    >
    > If Me!tglAllowEdit = True Then
    > Me!LockCode.Ena bled = True
    > Else
    > Me!LockCode.Ena bled = False
    > End If
    >
    > Exit_tglAllowEd it_Click:
    > Exit Sub
    >
    > Err_tglAllowEdi t_Click:
    > MsgBox Err.Description
    > Resume Exit_tglAllowEd it_Click
    >
    > End Sub
    >
    > For some others I get "Compile Error Label not defined"
    > Example code:
    >
    > Private Sub Form_Current()
    > On Error GoTo Err_Form_Curren t
    >
    > Me!LockCode.Ena bled = False
    >
    > Form_Current_Ex it:
    > End Sub
    >
    > Err_Form_Curren t:
    > MsgBox Err.Description
    > Resume Form_Current_Ex it
    >
    > End Sub
    >
    > I can't see the difference - can anyone tell me what I'm doing wrong?
    >
    > TIA
    >
    > Clive
    >
    >[/color]


    Comment

    • Clive Moss

      #3
      Re: Error Handling

      Thanks for the pointers Mike
      I should have known that, of course, but I am fairly new to this.

      Dumbos like me would be lost without you wizz types

      Clive


      "Mike Wiseley" <mike.wiseley@g te.net> wrote in message
      news:3sMcb.6537 $FH3.2213@nwrdd c02.gnilink.net ...[color=blue]
      > Simplify your error handling to use generic labels. You don't need labels
      > with specific names that are different for each procedure. This might help
      > reduce possible mistakes and confusion if you develop a lot of procedures.[/color]
      I[color=blue]
      > would have done your first procedure as follows:
      >
      > Private Sub Form_Current()
      > On Error GoTo Proc_Err
      >
      > Me!LockCode.Ena bled = False
      >
      > Proc_Exit:
      > Exit Sub
      >
      > Proc_Err:
      > MsgBox Err.Description
      > Resume Proc_Exit
      >
      > End Sub
      >
      > Also, your second procedure has two End Sub statements (incorrect) , while
      > the first procedure that you provided has an Exit Sub and an End Sub.
      >
      > "Clive Moss" <clive@REMOVEin stant-image.co.uk> wrote in message
      > news:GfKcb.590$ pG.5096592@news-text.cableinet. net...[color=green]
      > > Hi all
      > >
      > > Am I missing something here?
      > >
      > > I have a number of procedures where error code like this works fine:
      > > Eg:
      > > Private Sub tglAllowEdit_Cl ick()
      > > On Error GoTo Err_tglAllowEdi t_Click
      > >
      > > If Me!tglAllowEdit = True Then
      > > Me!LockCode.Ena bled = True
      > > Else
      > > Me!LockCode.Ena bled = False
      > > End If
      > >
      > > Exit_tglAllowEd it_Click:
      > > Exit Sub
      > >
      > > Err_tglAllowEdi t_Click:
      > > MsgBox Err.Description
      > > Resume Exit_tglAllowEd it_Click
      > >
      > > End Sub
      > >
      > > For some others I get "Compile Error Label not defined"
      > > Example code:
      > >
      > > Private Sub Form_Current()
      > > On Error GoTo Err_Form_Curren t
      > >
      > > Me!LockCode.Ena bled = False
      > >
      > > Form_Current_Ex it:
      > > End Sub
      > >
      > > Err_Form_Curren t:
      > > MsgBox Err.Description
      > > Resume Form_Current_Ex it
      > >
      > > End Sub
      > >
      > > I can't see the difference - can anyone tell me what I'm doing wrong?
      > >
      > > TIA
      > >
      > > Clive
      > >
      > >[/color]
      >
      >[/color]


      Comment

      Working...