Export (0) Print
Expand All
Expand Minimize

Visual Basic Reference

Visual Studio 6.0

DataField Property

See Also    Example    Applies To

Returns or sets the name of a field that a data consumer will be bound to.


object.DataField [= string]

The DataField property syntax has these parts:

Part Description
object An object expression that evaluates to an object in the Applies To list.
string A string expression that evaluates to the name of one of the fields in the Recordset object specified by a data source.


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 source, and the DataField property specifies a valid field name in the Recordset object created by the data source. 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"

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.

© 2014 Microsoft