AddNew

This method creates and initializes a new record for a Recordset object.

Syntax

recordset.AddNew Fields, Values

Parameters

Fields
Optional. Single name or an array that represents names or ordinal positions of the field(s) in the new record.
Values
Optional. Single value or an array that represents values for the field(s) 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 the 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

Dim rs, i, L1
Set rs = CreateObject("adoce.recordset")
rs.open "create table newtable (f1 varchar)"
rs.open "newtable", "", 1, 3
rs.addnew "f1", "a"
rs.addnew
rs.fields("f1") = "b"
rs.Update
rs.Close
rs.open "newtable"
For i = 0 To rs.recordcount - 1
L1 = L1 & rs.fields("f1").Value
rs.MoveNext
Next
rs.Close
MsgBox L1
rs.open "drop table newtable"
Set rs = Nothing