By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,460 Members | 2,215 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,460 IT Pros & Developers. It's quick & easy.

Error Handling

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.