HandsOn Experiments in the Immediate Window

1. Switch to the VBE window by pressing Alt+F11.

2. Press Ctrl+G to activate the Immediate window or choose View | Immediate Window.

3. In the Immediate window, type the instruction shown below, and press Enter:

Part I

DoCmd.OpenForm "Suppliers"

If you entered the above VBA statement correctly, Visual Basic opens the form Suppliers, assuming the Northwind database is currently open.

4. Enter the following instruction in the Immediate window:

Debug.Print Forms!Suppliers.RecordSource

When you press Enter, Visual Basic indicates that Suppliers is the RecordSource for the Suppliers form.

Every time you type an instruction in the Immediate window and press Enter, Visual Basic executes the statement on the line where the insertion point is located. If you want to execute the same instruction again, click anywhere in the line containing the instruction and press Enter. For more practice, rerun the statements shown in Figure 2-15. Start from the instruction displayed in the first line of the Immediate window. Execute the instructions one by one by clicking in the appropriate line and pressing Enter.

Figure 2-15: Use the Immediate window to evaluate and try out Visual Basic statements.

So far you have used the Immediate window to perform some actions. The Immediate window also allows you to ask questions. Suppose you want to find out the answers to "How many controls are in the Suppliers form?" or "What's the name of the current application?" When working in the Immediate window, you can easily get answers to these and other questions.

In the preceding exercise, you entered two instructions. Let's return to the Immediate window to ask some questions. Access remembers the instructions entered in the Immediate window even after you close this window. The contents of the Immediate window are automatically deleted when you exit Microsoft Access.

0 0

Post a comment