Lesson 7.15. Using the Control Wizard
Figure 7-25. You can turn the Control Wizard
Figure 7-26. The Combo Box Wizard.
Figure 7-27. Two interactive controls added to a form using the .
The Control Wizard (no relation to Merlin) helps you add powerful, interactive controls to your form, as shown in Figure 7-27. Some examples include:
List and combo box controls that can look up values in a table and then display the corresponding record on a form.
Buttons that can open, print, or close tables, forms, queries, pages, and reports.
Subforms, subreports, and charts that display related data from different tables.
When you add a control using the Control Wizard, you are asked a series of questions about what you want the control to do. The Control Wizard then creates the control, making the appropriate property settings and even adding several lines of Visual Basic code to the control for you.
Open the frmCustomers form in Design view.
To use the Control Wizard, simply make sure that the Control Wizards button on the Toolbox is shaded orange, as shown in Figure 7-25, and then add the control. The Control Wizard will appear anytime you try to create a list box, combo box, option group, button, chart, subreport, or subform.
Make sure the Control Wizards button on the Toolbox is pressed in.
The Control Wizard is so incredibly cool and useful that you are strongly recommended to always keep it on.
Note: If the Toolbox isn't displayed, click the Toolbox button on the Form Design toolbar.
First let's add a combo box control to the form.
Click the Combo Box button on the Toolbox.
The mouse pointer changes to a indicating that you can click and drag a combo box control on the form.
Place the pointer in the form header, about one inch to the right of the "Customers" label. Click and drag the pointer to the right about an inch and release the mouse button.
Because the Control Wizard is on, the appears, as shown in Figure 7-26. Each type of control will have its own Control Wizard and its own set of options. For this exercise, you want to select the third option.
Select the Find a record on my form based on the value I selected in my combo box option and click Next.
Next the Control Wizard asks which values you want to add to your combo box control
Click the button three times to add the CustomerID, LastName and FirstName fields to the combo box and click Next.
Next the Control Wizard asks how wide you want the columns in your combo box control and if you want to hide the key column. Everything looks okay here, so...
Finally, you are asked to give your combo box a name. You can accept the default name provided by the Control Wizard or you can provide your own name.
Type Lookup Name and click Finish.
Poof! The Control Wizard adds the combo box. Next let's add a command button that will print the current record when clicked.
Click the Command Button button on the Toolbox and add a button to the right of the CustomerID text box by clicking and dragging.
Because the Control Wizard is on, the Command Button Wizard appears. Command Buttons have lots of options that you can choose from, broken down by categories.
Select Record Operations from the Categories list and select Print Record from the Actions list.
This will make the command button print the current record when clicked.
Here you can specify the text or picture that will appear in the button.
Access adds the command button to the form.
Click the View button on the Form Design toolbar.
Let's see how our new controls work.
Select a name from the new Lookup Name combo box.
Access finds and displays the record that you select from the combo box.
Click the Close button to close the frmCustomers form and Yes to save.
Try experimenting and adding controls to your forms using the Control Wizard. You'll be amazed at how much you can accomplish without knowing any programming!
TO CREATE A LIST BOX OR COMBO BOX:
DISPLAY THE FORM IN DESIGN VIEW.
CLICK THE TOOLBOX BUTTON ON THE TOOLBAR, IF NECESSARY, AND MAKE SURE THE CONTROL WIZARDS BUTTON ON THE TOOLBOX IS SELECTED.
CLICK THE COMBO BOX OR LIST BOX BUTTON ON THE TOOLBOX.
IN THE FORM WINDOW, CLICK AND DRAG WHERE YOU WANT THE CONTROL TO APPEAR.
SPECIFY WHETHER YOU WANT THE CONTROL TO GET ITS VALUES FROM A TABLE OR QUERY, OR IF YOU WANT THE CONTROL TO FIND A RECORD ON THE FORM.
SELECT THE TABLE THAT CONTAINS THE FIELDS YOU WANT TO INCLUDE IN THE LIST AND CLICK NEXT.
SELECT THE FIELDS YOU WANT TO APPEAR IN YOUR LIST AND CLICK NEXT.
ADJUST THE COLUMN WIDTHS, IF NECESSARY, AND CLICK NEXT.
IF NECESSARY, SPECIFY WHICH COLUMN CONTAINS THE VALUE THAT WILL BE STORED AND CLICK NEXT.
SPECIFY WHETHER ACCESS SHOULD MERELY DISPLAY THE VALUE OR DISPLAY IT IN A FIELD.
ENTER A LABEL AND CLICK FINISH.