Debugging

Invariably, you will encounter errors in your code. Design-time and compile-time errors are relatively easy to deal with because Access helps us out with error messages and by indicating the offending code. Logical errors are much more difficult to detect and to fix. This is where debugging plays a major role. The Access IDE provides some very powerful ways to find bugs.

Debugging can be quite involved, and we could include a whole chapter on the subject. There are even special software applications designed to assist in complex debugging tasks. However, for most purposes, a few simple techniques are sufficient. In particular, Access makes it easy to trace through a program, executing one line at a time, watching the effect of each line as it is executed.

Let us discuss some of the tools that Access provides for debugging code.

Tracing

The process of executing code one line at a time is referred to as tracing or code stepping . Access provides three options related to tracing: stepping into, stepping over, and stepping out of. The difference between these methods refers to handling calls to other procedures.

To illustrate the difference, consider the code shown in Example 9.1. In ProcedureA, the first line of code adds a new record to a recordset denoted by rs. The second line calls ProcedureB and the third line updates the recordset. ProcedureB sets the value of the LastName and FirstName fields for the current record. Don’t worry about the exact syntax of this code. The ...

Get Access Database Design and Programming, Second Edition 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.