AddNew Method
Creates a new record for an updatable Recordset
object.
Syntax
recordset.AddNew Fields, Values
The AddNew method syntax has these parts:
|
Part
|
Description
|
|
recordset
|
An object variable representing the Recordset object to which you want
to add a new record.
|
|
Fields
|
Optional. A Variant representing a single name or a Variant
array representing names or ordinal positions of the field or fields in the
new record.
|
|
Values
|
Optional. A Variant representing a single value or a Variant
array representing values for the field or fields in the new record.
|
Remarks
Use the AddNew method to create and initialize a new record. Use the Supports
method to verify whether you may add records to the current Recordset
object.
After you call the AddNew method, the new record becomes the current
record and remains current after you call the Update
method. If the Recordset object supports bookmarks, the new record is
added to the end of the Recordset and remains visible. If the Recordset
object does not support bookmarks, you may not be able to access the new
record once you move to another record. To make the new record accessible, you
must call the Requery method.
If you call AddNew while editing the current record or while adding a
new record, ADO calls the Update method to save any changes and then
creates the new record.
If Fields is an array, Values must also be an
array with the same number of members; otherwise, an error occurs. The order
of field names must match the order of field values in each array.
The behavior of the AddNew method depends on the updating mode of the Recordset
object and whether or not you pass the Fields and Values
arguments.
In immediate update mode (the provider writes changes to the underlying data
source once you call the Update method), calling the AddNew
method without arguments sets the EditMode
property to adEditAdd. ADO caches any field value changes locally.
Calling the Update method posts the new record to the database and
resets the EditMode property to adEditNone. If you pass the Fields
and Values arguments, ADO immediately posts the new record to
the database (no Update call is necessary); the EditMode
property value does not change (adEditNone).
In batch update mode (the provider caches multiple changes and writes them to
the underlying data source only when you call the UpdateBatch
method), calling the AddNew method without arguments sets the EditMode
property to adEditAdd. ADO caches any field value changes locally.
Calling the Update method adds the new record to the current recordset
and resets the EditMode property to adEditNone, but the provider
does not post the changes to the underlying database until you call the UpdateBatch
method. If you pass the Fields and Values
arguments, ADO sends the new record to the provider for storage in a cache;
you need to call the UpdateBatch method to post the new record to the
underlying database.
Applies To
Recordset
See Also
CancelUpdate, EditMode,
Update
|