HandsOn Asking Questions in the Immediate Window

1. Click in a new line of the Immediate window and enter the following statement to find out the number of controls in the Suppliers form:

?Forms!Suppliers.Controls.Count

When you press Enter, Visual Basic enters the number of controls on a new line in the Immediate window.

Introduction to Access 2003 VBA Programming

2. Click in a new line of the Immediate window, and enter the following question:

?Application.Name

When you press Enter, Visual Basic enters the name of the active application on a new line in the Immediate window.

3. In a new line in the Immediate window, enter the following question:

When you press Enter, Visual Basic shows the result of division on a new line. But what if you want to know the result of 3 + 2 and 12*8 right away? Instead of entering these instructions on separate lines, you can enter them on one line as in the following example:

Notice the colon separating the two blocks of instructions. When you press the Enter key, Visual Basic displays the results 5 and 96 on separate lines in the Immediate window.

Here are a couple of other statements you may want to try out on your own in the Immediate window:

?Application.GetOption("Default Database Directory") ?Application.CodeProject.Name

Instead of using the question mark, you may precede the statement typed in the Immediate window with the Print command like this:

Print Application.CodeProject.Name

Later in this book you will learn how to run VBA procedures and functions from the Immediate window. To delete the instructions from the Immediate window, highlight all the lines and press Delete.

0 0

Post a comment