Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opinions on use of Error Trapping please... 1

Status
Not open for further replies.

mrf1xa

Technical User
Jan 14, 2002
366
GB
Hello all

I am doing some work on a database coded by someone else. I have come across this unnusual way (to me) of using errors:

A form is opened using a filter to restrict the records. In the on-current event of this form, there is code that checks and inserts a value in a text box. Fine so far.

The odd bit is that if the filter results in no records being displayed, Access throws up an error No 94, Invalid use of Null. My predeccessor has simply got around this by adding error handling which says 'If Err = 94...go to a new record instead'. My question is, is this good practise or is it likely to cause problems? It does seem to work OK...

Thanks Nigel
Didn't someone say work is supposed to be fun? They didn't have computers then I guess....
 
Nigel,

My thought is that there are two issues:
-does it work?
-does it make sense for the process?

It sounds like it works, when that error arises because there are no records. Is this the only way to get that error in this form? If not, you'll want to change it. If that is the only way to get that error in this form, the code is probably solid.

For the next question: Is it always, or nearly always, the case that if there are no records the user will add a new record? If so, then there's probably nothing wrong with it.

Hope this helps.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.
 
Thanks for the input Jeremy, especially the link which makes very intersting reading. Nigel
Didn't someone say work is supposed to be fun? They didn't have computers then I guess....
 
Nigel,

When I read your post, some questions came to mind:

1 - is the form based on a table whose primary key is a number field?

2 - if so, is there a code behind the form that dim this control?

3 - if not, then it is not what I am thinking.

4 - if so, then I would be curious to know if the dim statement refers to Integer or Variant.

Based on the design of your form, if an integer was used and the form's design meets my train of thought, you would get that sort of error. Changing integer for variant will most likely do the trick and you will not encounter an error (because variants handle Null but not integer).

Just my 5 cents worth,

Al
 
Al

Just tried this out and you are right, changing the Integer to a variant does avoid the error.

However, the question now is, should I leave the erro trapping as is and continue with Integer (the error is quite rare) or switch to variant? I was always told that variant should be used only as a last resort as it is far less efficient than integer for a numeric ID.

Thanks for the input. Nigel
Didn't someone say work is supposed to be fun? They didn't have computers then I guess....
 
Nigel,

That is exactly what error handling is for. Good practice as far as i'm concerned.

Craig
 
Nigel,

Interesting that I said leave it be before. In general, it's considered fairly sloppy coding to do things like use a variant instead of an integer and then trap for a null error. I would say that you should add a test for a null recordset and get rid of the trap for error 94. If you post the code, it will be easier to say, though.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top