Displaying Values in an Option Group


Whenever you have a field that contains an integer code value, you need to provide some way for the user to set the value based on what your application knows the code means, not the number. You could certainly use a combo box or a list box to supply a descriptive list. However, when the number of different values is small, an option group might be the ideal solution.

In the Conrad Systems Contacts application, the tblContacts table contains both a home and a work address. The DefaultAddress field contains an integer code value that is used by some reports to generate a mailing address. When DefaultAddress is 1, the application uses the work address; and when DefaultAddress is 2, the home address is the default. However, a user isn’t likely to always remember that 1. means work and 2. means home. You should provide a way to make these values obvious.

In the ContactsDataCopy.accdb sample file, you can find a form called frmXmplContacts that has the basic contact information and the two sets of addresses already laid out. Figure 13–25 shows you that form in Form view.

image from book
Figure 13–25: You can use this form to edit contact name and address information.

You can see that the Default Address field could be confusing on this form. To fix this, switch to Design view, and delete the DefaultAddress text box control. Click the Option Group button in the Controls group on the Design tab to select it, and then open the field list and drag the Default Address field onto the form under the Suffix combo box control. (We set the defaults for the option group control on this form so that it should fit nicely under the Suffix control and be wide enough to add some buttons.)

Next, double-click the Option Button command in the Controls group on the Design tab to allow you to define multiple buttons without having to go back to the Controls group to click the button again. When you move your mouse pointer inside the option group control, you’ll see the control become highlighted to indicate you’re placing the button inside the control. Drag one toward the left end of the control (the label will appear to the right of the button) and a second one to the middle. Figure 13–26 shows what the form looks like as you add the second button.

image from book
Figure 13–26: Add two option button controls inside an option group control.

Click the Select button in the Controls group on the Design tab to turn off the Option Button tool. Click the first button, and open the Property Sheet window. Near the top of the list on the All tab, you can see that Access has set the Option Value property of this button to 1. If you click the other button, you’ll find that its Option Value property is 2. Because the option group control is bound to the DefaultValue field, the first button will be highlighted when you’re on a record that has a value of 1 (work address) in this field, and the second button will be highlighted when the value is 2. If you click a different button when editing a record, Access changes the value of the underlying field to the value of the button.

You can actually assign any integer value you like to each option button in a group, but Access has set these just fine for this field. Note that if you assign the same value to more than one button, they’ll all appear selected when you’re on a record that has that value.

To make the purpose of these buttons perfectly clear, you need to fix the attached labels. Click the label for the first button, and change the Caption property from Option2 to Work. Set the Caption property for the label attached to the second button to Home. Switch to Form view to see the results as shown in Figure 13–27. Save this form as frmContacts2. You can also find this form saved as frmXmplContacts2 in the sample database.

image from book
Figure 13–27: You can use an option group to set the default address for the contacts.




Microsoft Office Access 2007 Inside Out
MicrosoftВ® Office Access(TM) 2007 Inside Out (Microsoft Office Access Inside Out)
ISBN: 0735623252
EAN: 2147483647
Year: 2007
Pages: 234

Similar book on Amazon
Access 2007: The Missing Manual
Access 2007: The Missing Manual
Microsoftu00ae Office Access(TM) 2007 Step by Step (Step By Step (Microsoft))
Microsoftu00ae Office Access(TM) 2007 Step by Step (Step By Step (Microsoft))
Microsoft Office Access 2007 Forms, Reports, and Queries
Microsoft Office Access 2007 Forms, Reports, and Queries
Alison Balter's Mastering Microsoft Office Access 2007 Development
Alison Balter's Mastering Microsoft Office Access 2007 Development

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