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 ...
Get Access 2010: The Missing Manual now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.