ControlSource Property

Applies To

Bound Object Frame Control, Check Box Control, Combo Box Control, List Box Control, Option Button Control, Option Group Control, Text Box Control, Toggle Button Control.

Description

You can use the ControlSource property to specify what data appears in a control. You can display and edit data bound to a field in a table, query, or SQL statement. You can also display the result of an expression. For a report group level, the ControlSource property determines the field or expression to group on.

Note The ControlSource property doesn’t apply to check box, option button, or toggle button controls in an option group. It applies only to the option group itself.

For reports, the ControlSource property applies only to report group levels.

Setting

The ControlSource property has the following settings.

Setting Description
A field name The control is bound to a field in a table, query, or SQL statement. Data from the field is displayed in the control. Changes to the data inside the control change the corresponding data in the field. (To make the control read-only, set the Locked property to Yes.)
An expression The expression generates data for the control. This data is read-only and is not saved in the database.


You can set the ControlSource property for a control using the control’s property sheet, a macro, or Visual Basic. You can also set the ControlSource property for a text box by typing a field name or expression directly in the text box in form or report Design view.

For a report, you can set this property by selecting a field or typing an expression in the Field/Expression column of the Sorting And Grouping box. For details, see the GroupLevel property.

In Visual Basic, use a string expression to set the value of this property.

Remarks

Forms and reports act as “windows” into your database. You specify the primary source of data for a form or report by setting its RecordSource property to a table, query, or SQL statement. You can then set the ControlSource property to a field in the source of data or to an expression. If the ControlSource property setting is an expression, the value displayed is read-only and not saved in the database. For example:

Example Setting Description
LastName A field name in the source specified by the RecordSource property of a form or report. For a control, data from the LastName field is displayed in the control. For a report group level, Microsoft Access groups the data on last name.
= Date( ) + 7 An expression. For a control, this expression displays a date seven days from today in the control.
= DatePart(“q”,[ShippedDate]) An expression. For a control, this expression displays the quarter of the shipped date. For a report group level, Microsoft Access groups the data on the quarter of the shipped date.


See Also

Load, Unload Events; RecordSource Property; RowSourceType, RowSource Properties.

Example

The following example sets the ControlSource property for a text box named AddressPart to a field named City.


Forms![Customers]![AddressPart].ControlSource = "City"

The next example sets the ControlSource property for a text box named Expected to the expression = Date() + 7.


Forms![Invoice]![Expected].ControlSource = "= Date() + 7"