The Command Button Wizard: Programming Without Typing

With the Command Button Wizard, you can quickly and easily add functionality to forms. The wizard writes the code to perform more than 30 commonly required tasks that are separated into record navigation, record operations, form operations, report operations, application operations, and other miscellaneous tasks. The Command Button Wizard is automatically invoked when you add a command button with the Control Wizards tool selected. The first step of the Command Button Wizard is shown in Figure 16.12; in this dialog box you specify the category of activity and specific action you want the command button to perform. The subsequent wizard steps vary, depending on the category and action you select.

Figure 16.12. The first step of the Command Button Wizard.


Figure 16.13 shows the second step of the Command Button Wizard when you select the Form Operations category and the Open Form action in the first step. This step asks which form you want to open. After you select a form and click Next, you're asked whether you want Access to open the form and find specific data to display or whether you want Access to open the form and display all the records. If you indicate that you want to display only specific records, the dialog box shown in Figure 16.14 appears. This dialog box asks you to select fields related to the two forms. You must select the related fields and then click the double-arrow (<>) button to notify Access of the relationship. In the next step of the wizard, you select text or a picture for the button. The final step of the wizard asks you to name the button. When you're done, you click Finish.

Figure 16.13. The Command Button Wizard, requesting the name of a form to open.


Figure 16.14. The Command Button Wizard, asking for the fields that relate to each form.


What's surprising about the Command Button Wizard is how much it varies depending on the features you select. It allows you to add somewhat sophisticated functionality to an application without writing a single line of code. Figure 16.15 shows the code generated by the example just outlined. This code will make a lot more sense to you after you've read Hour 23, "VBA Introduced." After you have the Command Button Wizard generate code for you, you can modify it; this means that you can have Access do some of the dirty work for you and then customize the work to your liking.

Figure 16.15. Code generated by the Command Button Wizard.


    Part III: Creating Your Own Database and Objects
    Part V: Advanced Topics