The Immediate Window

The Immediate window (see Figure 8.1) has two main functions. First, we can send output to this window using the command Debug.Print. For instance, the code shown in Figure 8.5 produces the result shown in the Immediate window (there were four records in the recordset when I executed this code). (We will see how to execute the code in a procedure shortly.) This provides a nice way to experiment with different code snippets.

The other main function of the Immediate window is to execute commands. We can enter a line of code directly in the Immediate window. Hitting the Enter key at the end of the line asks Access to execute that line of code. Note that this only works for single physical lines of code, but you can place more than one logical line of code on the same physical line by separating the logical lines with colons, as in:

For i = 1 To 10: Debug.Print i: Next i
The Immediate Window

Figure 8-5. The Immediate Window

The Immediate window is an extremely valuable tool for debugging a program, and you will probably use it often (as I do).

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.