DataField Property (DataGrid Control, Column Object)

       

Returns or sets a value that binds a control to a field in the current record

Syntax

object.DataField [= value]

The DataField property syntax has these parts:

Part Description
object An object expression that evaluates to an object in the Applies To list.
value A string expression that evaluates to the name of one of the fields in the Recordset object specified by a data control's RecordSource and DatabaseName properties.

Remarks

Bound controls provide access to specific data in your database. Bound controls that manage a single field typically display the value of a specific field in the current record. The DataSource property of a bound control specifies a valid data control name, and the DataField property specifies a valid field name in the Recordset object created by the data control. Together, these properties specify what data appears in the bound control.

When you use a QueryDef object or SQL statement that returns the results of an expression, the field name is automatically generated by the Microsoft Jet database engine. For example, when you code an SQL aggregate function or an expression in your SQL query, unless you alias the aggregate fields using an AS clause, the field names are automatically generated. Generally, the expression field name is Expr1 followed by a three-character number starting with 000. The first expression returned would be named Expr1000.

It's recommended that you code your SQL queries to alias expression columns as shown below:

Adodc1.RecordSource = "Select AVG(Sales)  " _
   & " AS AverageSales From SalesTable"
Text1.DataField = "AverageSales"
Adodc1.Refresh

Note   Make sure the DataField property setting is valid for each bound control. If you change the setting of a data control's RecordSource property and then use Refresh, the Recordset identifies the new object. This may invalidate the DataField settings of bound controls and produce a trappable error.

Data Type

String