O'Reilly logo

Access 2010: The Missing Manual by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Dealing with Trouble

It would be nice to pretend that Access always sails through your code without the slightest hiccup. But the truth is, errors do occur, and they occur often. This fact shouldn’t frighten you. After all, one of the reasons you’re using Visual Basic code instead of ordinary macros is so that you can detect and respond to errors gracefully.

You’ll face two types of errors with your code:

  • Mistakes. These errors are coding errors that you introduce accidentally. Usually, you catch these while testing your database. (If you’re lucky, the Visual Basic editor spots the problem as soon as you type it in and then warns you with a message.)

  • Unexpected limitations. These errors arise under specific circumstances that you may not have anticipated. Say you create two forms: Order, and Order_Subform. Order_Subform is designed to be used as a subform in Order, and it includes code that accesses the controls in Order. However, if someone opens Order_Subform directly, the Order form isn’t available, and this code fails.

As a conscientious programmer, it’s your job to correct all your mistakes and deal with unforeseen limitations in the best possible way. Visual Basic gives you two tools to help out. You can use debugging to diagnose bizarre problems and fix them, and you can use error-handling code to catch unexpected problems and to alert other people.

Debugging

Debugging is a nifty feature that lets you walk through your code, watch what it does, and spot errors. Code debugging is ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required