Microsoft Access 2010 Bible

(Rick Simeone) #1

Chapter 10: VBA Programming Fundamentals


395


Creating a new procedure
After you complete any declarations for the module, you’re ready to create a procedure. Follow
these steps to create a procedure called BeepWarning:


  1. Open the Module1 module you previously created, as shown in Figure 10.9.

  2. Go to any empty line in the code window.

  3. Type the code in exactly as shown in Figure 10.10.


FIGURE 10.10
Entering a new procedure in the code window


  1. Save the module (the save button is in the VBA editor’s toolbar), naming it
    basBeepWarning.


Notice that, as you entered the first line of the procedure, Access automatically added the End Sub
statement to the procedure.

In this example, you’re running the program five times. The completed function should look like
the one shown in Figure 10.10.

When BeepWarning actually runs, the five beeps will almost certainly blend together as a single
beep from your computer’s speaker.

If you enter the name of a function you previously created in this module (or in another module
within the database), Access informs you that the function already exists. Access doesn’t enable
you to create another procedure with the same name.

Using IntelliSense
Suppose that you know you want to use a specific command, but you can’t remember the exact
syntax. Access features two types of IntelliSense to help you create each line of code:
Free download pdf