469,913 Members | 1,947 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,913 developers. It's quick & easy.

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_Click()
On Error GoTo Err_tglAllowEdit_Click

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

Exit_tglAllowEdit_Click:
Exit Sub

Err_tglAllowEdit_Click:
MsgBox Err.Description
Resume Exit_tglAllowEdit_Click

End Sub

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

Private Sub Form_Current()
On Error GoTo Err_Form_Current

Me!LockCode.Enabled = False

Form_Current_Exit:
End Sub

Err_Form_Current:
MsgBox Err.Description
Resume Form_Current_Exit

End Sub

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

TIA

Clive
Nov 12 '05 #1
2 6999
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.Enabled = 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" <cl***@REMOVEinstant-image.co.uk> wrote in message
news:Gf******************@news-text.cableinet.net...
Hi all

Am I missing something here?

I have a number of procedures where error code like this works fine:
Eg:
Private Sub tglAllowEdit_Click()
On Error GoTo Err_tglAllowEdit_Click

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

Exit_tglAllowEdit_Click:
Exit Sub

Err_tglAllowEdit_Click:
MsgBox Err.Description
Resume Exit_tglAllowEdit_Click

End Sub

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

Private Sub Form_Current()
On Error GoTo Err_Form_Current

Me!LockCode.Enabled = False

Form_Current_Exit:
End Sub

Err_Form_Current:
MsgBox Err.Description
Resume Form_Current_Exit

End Sub

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

TIA

Clive

Nov 12 '05 #2
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" <mi**********@gte.net> wrote in message
news:3s*****************@nwrddc02.gnilink.net...
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.Enabled = 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" <cl***@REMOVEinstant-image.co.uk> wrote in message
news:Gf******************@news-text.cableinet.net...
Hi all

Am I missing something here?

I have a number of procedures where error code like this works fine:
Eg:
Private Sub tglAllowEdit_Click()
On Error GoTo Err_tglAllowEdit_Click

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

Exit_tglAllowEdit_Click:
Exit Sub

Err_tglAllowEdit_Click:
MsgBox Err.Description
Resume Exit_tglAllowEdit_Click

End Sub

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

Private Sub Form_Current()
On Error GoTo Err_Form_Current

Me!LockCode.Enabled = False

Form_Current_Exit:
End Sub

Err_Form_Current:
MsgBox Err.Description
Resume Form_Current_Exit

End Sub

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

TIA

Clive


Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Christian Christmann | last post: by
13 posts views Thread by Thelma Lubkin | last post: by
3 posts views Thread by Stefan Johansson | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.