The first step in avoiding or fixing bugs is understanding the three kinds of errors you can encounter:
Unless you’ve cleared the Auto Syntax Check check box on the Module tab of the Options dialog box (Tools menu), Visual Basic displays an error message whenever you enter code that contains a syntax error.
Speed = Miles / Hours
If the variable Hours
is equal to zero, a division by zero error occurs even though the statement itself is syntactically correct. The error is a run-time error because the code must run before Visual Basic can detect the error. Not all run-time errors are easily anticipated or fixed. For example, a “Disk full” error may require you to cancel an update and restore a table to its initial state. If you don’t trap run-time errors, Microsoft Access will stop your code at the place where the error occurred and display the error message associated with that error.
See Also For more information on fixing run-time errors, see Chapter 8, “Handling Run-Time Errors.”
Because successful debugging requires that you understand what’s going on when your code runs, you’ll want to design code that’s easy to analyze. Try the following techniques when designing your code to make the debugging process easier: