Lesson 7.12. Changing a Control's Data Source
Figure 7-17. Examples of bound, unbound, and calculated controls
Figure 7-18. Setting the Control Source property
Figure 7-19. The steps in modifying a control's text label.
There are three types of controls that you can add to your forms, as illustrated in Figure 7-17. They are:
Bound Controls: Bound controls are bound or connected to an underlying field in a table or query. You use to display, enter, and update field values in your database. The fields that you can add to a form using the Field List are all examples of .
Unbound Controls: Unbound controls are not bound or connected to an underlying field in a table or query. You use to display information. Labels, text boxes, and buttons can all be inserted on a form as . The two check boxes you added to the form in the previous lessons are both examples of unbound controls because they aren't connected to an underlying field in a table or query.
Calculated Controls: Calculated controls are based on an expression and are used to calculate values in a form, such as arithmetic problems. Technically, are unbound controls because they do not update any table fields.
A control's Control Source property determines what is displayed in a controlhere's how:
A bound control's Control Source property contains the name of the underlying database field to which it is bound.
An unbound control's Control Source property does not contain the name of an underlying database field.
A calculated control's Control Source property contains an expression that calculates the values displayed in the control.
This lesson explains how you can change a control's Control Source property.
Select the first check box control you added in the previous lesson, and display its properties by clicking the Properties button on the Form Design toolbar.
The Properties dialog box appears. You can find the Control Source property on the Data Tab.
Click the Data tab.
The Data tab appears, as shown in Figure 7-18. You can determine what is displayed in the control by setting the Control Source property. You can bind the control to a field in the form's underlying query or table by clicking the button, or you can type text or an expression directly into the Control Source box. We want to bind the selected check box to the Smoker field.
Click in the Control Source box, click the button, and select Smoker from the list, as shown in Figure 7-18.
The check box is now bound to the Smoker field in the tblCustomers table. Next let's bind the other check box control you added to the First Class field.
With the Properties dialog box still open, click the second check box control you added in the previous lesson.
The Properties dialog box is updated and displays the settings for the selected check box control.
Click in the Control Source box, click the button, and select First Class from the list.
You're done specifying the data sources for the two check boxes so you can close the Properties dialog box.
Click the Close button to close the Properties dialog box.
Before we're finished, we have to give the two check boxes more meaningful text labels. Here's how:
Position the pointer over the first check box text label, until it changes into a , and then click inside the text label, as illustrated in Figure 7-19.
Now you can edit the check box text label.
Replace the text label text with Smoker.
Now move on to the next step and change the text label for the second check box.
Following the same procedures as Steps 7-8, rename the second check box text label First Class.
That's it! You're done binding the check boxes to two underlying database fields.
Click on the Close button to close the frmCustomers form and click Yes to save your changes.
TO CHANGE A CONTROL'S DATA SOURCE:
DISPLAY THE FORM IN DESIGN VIEW.
SELECT THE CONTROL AND CLICK THE PROPERTIES BUTTON ON THE TOOLBAR.
RIGHT-CLICK THE CONTROL AND SELECT PROPERTIES FROM THE SHORTCUT MENU.
SELECT THE CONTROL AND SELECT VIEW
CLICK THE DATA TAB.
CLICK THE CONTROL SOURCE BOX, CLICK THE ARROW, AND SELECT THE FIELD THAT YOU WANT TO BIND THE CONTROL TO.
CLICK THE CONTROL SOURCE BOX AND ENTER AN EXPRESSION.
CLOSE THE PROPERTIES DIALOG BOX.