473,387 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 7210
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: WSeeger | last post by:
When creating a new class, is it encouraged to always include error handling routines within your LET and GET procedures? It's seems that most text books never seem to include much about error...
12
by: Christian Christmann | last post by:
Hi, assert and error handling can be used for similar purposes. When should one use assert instead of try/catch and in which cases the error handling is preferable? I've read somewhere that...
6
by: Squirrel | last post by:
I have a command button on a subform to delete a record. The only statement in the subroutine is: DoCmd.RunCommand acCmdDeleteRecord The subform's recordsource is "select * from tblVisit order...
13
by: Thelma Lubkin | last post by:
I use code extensively; I probably overuse it. But I've been using error trapping very sparingly, and now I've been trapped by that. A form that works for me on the system I'm using, apparently...
21
by: Anthony England | last post by:
Everyone knows that global variables get re-set in an mdb when an un-handled error is encountered, but it seems that this also happens when the variable is defined as private at form-level. So...
3
by: Stefan Johansson | last post by:
Hi all I'am moving from Visual Foxpro and have a question regarding "best practice" error handling in vb .net. In VFP I have always used a "central" error handling object in order to have a...
4
by: Al Williams | last post by:
Hi, I have error handling in place throughout my application. I also start the application wrapped in error handling code to catch any unexpected exceptions (i.e. exceptions that occur where I...
10
by: Anthony England | last post by:
(sorry for the likely repost, but it is still not showing on my news server and after that much typing, I don't want to lose it) I am considering general error handling routines and have...
0
by: Lysander | last post by:
Thought I would give something back with a few articles. This article is a bit of code to add error handling. When I have time, I want to write articles on multilingual databases, and Access...
9
by: MrDeej | last post by:
Hello guys! We have an SQL server which sometimes makes timeouts and connection errors. And we have an function witch writes and updates data in 2 tables on this server. When the SQL server error...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.