Microsoft Access 2010 Bible

(Rick Simeone) #1

Chapter 10: VBA Programming Fundamentals


385


Using the Command Button Wizard
One option when adding a button to an Access form is to use the Command Button Wizard.
When Access creates a command button with a wizard, it adds an embedded macro attached to the
button. The embedded macro performs whatever action (open form, open report, and so on) that
you specified when you worked with the wizard. You can open the embedded macro in the macro
editor (described in Chapters 15 and 30) and modify it to fit your needs.

Access supports more than 30 types of command buttons through the Command Button Wizard.
These buttons include finding or printing records, as well as applying a filter to a form’s data. Run
this wizard by adding a command button to a form with the Use Control Wizards option selected
in the Design tab of the Access ribbon. (You have to expand the controls palette to see the Use
Control Wizards option.) Figure 10.4 shows a Go To Next Record command button being created.
Notice that the Command Button Wizard even shows a preview of the image it selects for the but-
ton in the panel at the left side of the wizard dialog box.

FIGURE 10.4

The Command Button Wizard


The Chapter10.accdb example database includes a form named frmButtonWizardSam-
ples_Macros. This form, shown in Figure 10.5 in Design mode, contains a dozen command
buttons created with the Command Button Wizard. Review the procedures for the buttons on this
form to see how powerful Access macros can be. The buttons on this form don’t actually do any-
thing because there is no data on the form, and the macros have nothing to actually work with, but
they show the variety of actions supported by the command button wizard.

Figure 10.6 shows the code for the Go To First Record command button.

The macro produced by the Command Button Wizard is very simple but effective.
Free download pdf