OrdinalPosition Property

See Also   Applies To

Sets or returns the relative position of a CdbField object within a Fields collection.

Syntax

VOIDSetOrdinalPosition(SHORT sPosition);

SHORTGetOrdinalPosition(VOID);

Parameters

Type Argument Description
SHORT sPosition A Short that specifies the numeric order of the field.

Remarks

The availability of the OrdinalPosition property depends on the object that contains the Fields collection, as shown in the following table.

If the Fields collection belongs to a Then OrdinalPosition is
CdbIndex object Not supported
CdbQueryDef object Read-only
CdbRecordset object Read-only
CdbRelation object Not supported
CdbTableDef object Read/write

For an object not yet appended to the Fields collection, this property is read/write and the default value is 0.

Generally, the ordinal position of an object that you append to a collection depends on the order in which you append the object. The first appended object is in the first position (0), the second appended object is in the second position (1), and so on. The last appended object is in ordinal position count – 1, where count is the number of objects in the collection as specified by the Count property setting.

You can use the OrdinalPosition property to specify an ordinal position for new CdbField objects that differs from the order in which you append those objects to a collection. This enables you to specify a field order for your tables, queries, and recordsets when you use them in an application. For example, the order in which fields are returned in a SELECT * query is determined by the current OrdinalPosition property values.

You can permanently reset the order in which fields are returned in recordsets by setting the OrdinalPosition property to any positive integer.

Two or more CdbField objects in the same collection can have the same OrdinalPosition property value, in which case they will be ordered alphabetically. For example, if you have a field named Age set to 4 and you set a second field named Weight to 4, Weight is returned after Age.

You can specify a number that is greater than the number of fields minus 1. The field will be returned in an order relative to the largest number. For example, if you set a field's OrdinalPosition property to 20 (and there are only 5 fields) and you've set the OrdinalPosition property for two other fields to 10 and 30, respectively, the field set to 20 is returned between the fields set to 10 and 30.

Note Even if the Fields collection of a CdbTableDef has not been refreshed, the field order in a CdbRecordset opened from the CdbTableDef will reflect the OrdinalPosition data of the CdbTableDef object. A table-type CdbRecordset will have the same OrdinalPosition data as the underlying table, but any other type of CdbRecordset will have new OrdinalPosition data (starting with 0) that follow the order determined by the OrdinalPosition data of the CdbTableDef.