Class Fields (ADODB VBA)

Contains all the Field objects of a Recordset or Record object. To use a Fields class variable it first needs to be instantiated, for example

Append

Appends an object to a collection. If the collection is Fields, a new Field object may be created before it is appended to the collection.

Append (Name, Type, DefinedSize, Attrib, FieldValue)

Arguments

The following arguments are required:

Name (String) - A String value that contains the name of the new Field object, and must not be the same name as any other object in fields.

Type (DataTypeEnum) - A DataTypeEnum value, whose default value is adEmpty, that specifies the data type of the new field. The following data types are not supported by ADO, and should not be used when appending new fields to a Recordset: adIDispatch, adIUnknown, adVariant.

Here you can find possible values for DataTypeEnum

Optional arguments

The following arguments are optional

DefinedSize - A Long value that represents the defined size, in characters or bytes, of the new field. The default value for this parameter is derived from Type. Fields with a DefinedSize greater than 255 bytes, and treated as variable length columns. (The default DefinedSize is unspecified.)

Attrib (FieldAttributeEnum) - A FieldAttributeEnum value, whose default value is adFldDefault, that specifies attributes for the new field. If this value is not specified, the field will contain attributes derived from Type.

Here you can find possible values for FieldAttributeEnum

FieldValue - A Variant that represents the value for the new field. If not specified, then the field is appended with a null value

CancelUpdate

Cancels any changes made to the current or new row of a Recordset object, or the Fields collection of a Record object, before calling the Update method.

Recordset Use the CancelUpdate method to cancel any changes made to the current row or to discard a newly added row. You cannot cancel changes to the current row or a new row after you call the Update method, unless the changes are either part of a transaction that you can roll back with the RollbackTrans method, or part of a batch update. In the case of a batch update, you can cancel the Update with the CancelUpdate or CancelBatch method. If you are adding a new row when you call the CancelUpdate method, the current row becomes the row that was current before the AddNew call. If you are in edit mode and want to move off the current record (for example, with Move, NextRecordset, or Close), you can use CancelUpdate to cancel any pending changes. You may need to do this if the update cannot successfully be posted to the data source (for example, an attempted delete that fails due to referential integrity violations will leave the Recordset in edit mode after a call to Delete). Record The CancelUpdate method cancels any pending insertions or deletions of Field objects, and cancels pending updates of existing fields and restores them to their original values. The Status property of all fields in the Fields collection is set to adFieldOK.

Count

Indicates the number of objects in a collection.

Use the Count property to determine how many objects are in a given collection. Because numbering for members of a collection begins with zero, you should always code loops starting with the zero member and ending with the value of the Count property minus 1. If you are using Microsoft Visual Basic and want to loop through the members of a collection without checking the Count property, use the For Each...Next command. If the Count property is zero, there are no objects in the collection.

Delete

Deletes an object from the Fields collection.

Calling the Fields.Delete method on an open Recordset causes a run-time error.

Delete (Index)

Item

Indicates a specific member of a collection, by name or ordinal number.

Use the Item property to return a specific object in a collection. If Item cannot find an object in the collection corresponding to the Index argument, an error occurs. Also, some collections don't support named objects; for these collections, you must use ordinal number references. The Item property is the default property for all collections; therefore, the following syntax forms are interchangeable:

Item (Index)

Index: A Variant expression that evaluates either to the name or to the ordinal number of an object in a collection.

Refresh

Updates the objects in a collection to reflect objects available from, and specific to, the provider.

The Refresh method accomplishes different tasks depending on the collection from which you call it.

Resync

Refreshes the data in the current Recordset object, or Fields collection of a Record object, from the underlying database.

Resync (ResyncValues)

ResyncValues: A ResyncEnum value that specifies whether underlying values are overwritten. The default value is adResyncAllValues.

Update

Saves any changes you make to the current row of a Recordset object, or the Fields collection of a Record object.