Adding Option Groups with the Wizard

Option buttons, toggle buttons, and check boxes ordinarily return only Yes/No ( 1/0 or True/False) values when used by themselves on a form. These three controls also can return Null values if you change the TripleState property value to Yes. Individual bound option button controls are limited to providing values to Yes/No fields of a table or query. When you place any of these controls within an option group, however, the buttons or check boxes can return a number you specify for the value of the control's Option Value property.

The capability to assign numbers to the Option Value property lets you use one of the preceding three controls inside an option group frame for assigning values to the HRRating field of the HRActions table. Option buttons are most commonly used in Windows applications to select one value from a limited number of values.

The Option Group Wizard is one of three Control Wizards that take you step-by-step through the creation of complex controls. To create an option group for the HRRating field of the HRActions table with the Option Group Wizard, follow these steps:

  1. graphics/build_wizard.gif Click the Control Wizards tool to turn on the wizards if the toggle button isn't On (the default value).

    Note

    Access's toggled Toolbox (and toolbar) buttons indicate the On (True) state by a border with a colored background under Windows XP or a white background under Windows 2000. This differs from toggle buttons on forms, which use a very light gray background and a sunken effect to indicate the On (pressed) state. Background colors differ if you've applied a Windows XP desktop theme.

  2. graphics/option_group.gif Click the Option Group tool, position the pointer where you want the upper-left corner of the option group, and click the mouse button to display the first dialog of the Option Group Wizard.

  3. For this example, type five of the nine ratings in the Label Names datasheet (pressing Tab, not Enter): Excellent, Good, Acceptable, Fair, and Poor(see Figure 15.13). Click Next.

    Figure 15.13. Type the caption for each option button of the option group in the first dialog of the Option Group Wizard.

    graphics/15fig13.gif

    Tip

    You can specify accelerator keys in the captions of your option buttons by placing an ampersand (&) before the letter to be used as an accelerator key. Thereafter, pressing Alt in combination with that letter key selects the option when your form is in Run mode. To include an ampersand in your caption, type &&.

  4. The second dialog lets you set an optional default value for the option group. Select the option named Yes, the Default Choice Is, and open the drop-down list. Select Good, as shown in Figure 15.14, and click Next. If you need to, you can return to any previous step by clicking Back one or more times.

    Figure 15.14. Select a default value in the second Option Group Wizard dialog.

    graphics/15fig14.gif

  5. graphics/access_2002_new_icon.gif

    The third dialog of the Option Group Wizard provides for the assignment of option values to each option button of the group. The default value is the numbered sequence of the buttons. Type 9, 7, 5, 3, and 1 in the five text boxes, as illustrated in Figure 15.15, and click Next.

    Figure 15.15. Assign a numeric value to each option button in the group. In Form view, clicking an option button assigns its value to the option frame.

    graphics/15fig15.gif

    Note

    The domain integrity rule for the HRRating field provides for nine different ratings. Nine option buttons, however, occupy too much space on a form, so this example uses only five of the nine ratings. (Only 5 of the 9 options are included here for the sake of simplicity. In the real world, you wouldn't just eliminate options because there are too many.)

  6. The fourth Wizard dialog lets you bind the option group to a field of a table or a column of a query that you specified as the Record Source property value of the bound form. Select the HRRating column of the qryHRActions query to which your form is bound (see Figure 15.16). Click Next.

    Figure 15.16. Bind the option group value.

    graphics/15fig16.gif

  7. The fifth dialog lets you determine the style of the option group, as well as the type of controls (option buttons, check boxes, or toggle buttons) to add to the option group. You can preview the appearance of your option group and button style choices in the Sample pane. For this example, select Option Buttons and Sunken (see Figure 15.17). The sunken effect matches the default effect applied to text boxes.

    Figure 15.17. The fifth Wizard dialog lets you choose the option frame's control type and appearance.

    graphics/15fig17.gif

    Note

    Check boxes are an inappropriate choice for controls in an option group. Windows programming standards reserve multiple check boxes for situations in which more than one option choice is permissible.

    The sunken and raised styles of option groups, option buttons, and check boxes are applicable only to control objects on forms or option groups with a Back Color property other than white.

  8. The last dialog provides a text box for entering the Caption property value of the label for the option group. Type Rating, as shown in Figure 15.18, and click Finish to let the Wizard complete its work.

    Figure 15.18. Add the caption for the option group in the last Wizard dialog.

    graphics/15fig18.gif

  9. graphics/properties_window.gif Open the Properties dialog for the option frame, and assign the frame a name, fraRating for this example. Figure 15.19 shows the completed Rating option group and its properties window in Form Design view.

    Figure 15.19. The Properties dialog for the fraRating option frame displays the property values assigned by the Wizard.

    graphics/15fig19.gif

Tip

Name the controls you add to identify their use, rather than accepting Access default value for the Name property. This book uses object-naming conventions that consist of a three-letter, lowercase abbreviation of the object type fra for frames, txt for text boxes, frm for forms, and the like followed by a descriptive name for the control. Using a consistent object naming convention makes it much easier to write (and later interpret) VBA code for automating your application.

Access 2000 added the capability to change property values in Form view. However, you can change the Name property value of an object only in Form Design view.


For more information on Access and VBA naming conventions, see "Typographic and Naming Conventions Used for VBA," p. 1152.


graphics/text_box.gif To test your new bound option group, select the Text Box tool and drag the HRRating field from the field list to the form to add a text box that's bound to the HRRating column. Figure 15.20 shows the option group in Form view with the Bold attribute applied to the option group label and the Rating text box added. Click the option buttons to display the rating value in the text box. Although your entry on the form tentatively updates the value onscreen, the value in the table doesn't change until you move the record pointer or change the view of the form. Press Ctrl+S to save your form.

Figure 15.20. Clicking an option button displays its value in the HRRating text box and makes a tentative change to the HRRating field of the current record of the HRActions table.

graphics/15fig20.gif

Changing One Control Type to Another

Access lets you "morph" a control of one type to become a control of a compatible type. You can change an option button to a check box, for example, or you can change a toggle button to an option button. You can't, however, change a text box to an object frame or other control with a different field data type. To change a control to a different type, follow these steps:

  1. In the form's Design view, select the control whose type you want to change.

  2. Choose Format, Change To to see a submenu of form control types. Only the submenu choices for control types that are compatible with the selected control are enabled.

  3. Select the control type you want from the submenu. Access changes the control type.



Special Edition Using Microsoft Office Access 2003
Special Edition Using Microsoft Office Access 2003
ISBN: 0789729520
EAN: 2147483647
Year: 2005
Pages: 417

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net