AddNew

This method inserts a new row into a recordset.

Syntax

recordset.AddNew Fields, Values

Parameters

Fields

Optional. Single name or an array that represents names or ordinal positions of the fields in the new record.

Values

Optional. Single value or an array that represents values for the fields in the new record.

Remarks

Use the Supports method (Const adAddNew = &H01000400) to verify whether you can add records to the current Recordset object. You cannot add records if you open a recordset with the default LockType (Const adLockReadOnly = 1).

After you call the AddNew method, the new record becomes the current record and remains current after you call the Update method. ADOCE adds the new record to the end of the Recordset object.

If you call AddNew while editing the current record or while adding a new record, ADOCE first 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.

Calling the AddNew method without parameters sets the EditMode property to 2 (adEditAdd) and causes ADOCE to cache any field value changes locally. Calling the Update method posts the new record to the database and resets the EditMode property to 0 (adEditNone). If you pass the Fields and Values parameters, ADOCE immediately posts the new record to the database. No Update call is necessary because the EditMode property value does not change from 0 (adEditNone).

ADOCE always updates in immediate mode. Batch mode is not supported.

Example

The following code example shows how to add a new field to a table using the AddNew method, and then displays the values of the new field in a message box.

Dim rs, i, L1
Set rs = CreateObject("adoce.recordset")
rs.Open "myTable", "", 1, 3
rs.AddNew "f1", "a"
rs.AddNew
rs.Fields("f1") = "b"
rs.Update
rs.Close
rs.Open "myTable"
For i = 0 To rs.RecordCount - 1
L1 = L1 & rs.Fields("f1").Value
rs.MoveNext
Next
rs.Close
MsgBox L1