Databases Reference
In-Depth Information
rs.Close
MsgBox Format$(DeleteCt) & " records deleted."
End
Sub
16.5.3 Adding a New Record
Adding a new record to a recordset is done in three steps:
1.
Invoke the
AddNew
method to create a blank record, which Jet makes the current
record.
2.
Fill in the fields of the record.
3.
Invoke the
Update
method to save the record.
The syntax of the
AddNew
method is simply:
RecordsetVar
.AddNew
16.5.3.1 Notes
Once the
Update
method is invoked, the record that was the current record
prior
to invoking the
AddNew
method again becomes the current record. To make the
new record current, use a bookmark together with the LastModified property, as
shown in Example 16-8.
•
In a table-type recordset, the new record is placed in its proper order with respect
to the current index. In a dynaset-type recordset, the new record is placed at the
end of the recordset. If the recordset has a sort order (such as might be inherited
from an underlying query), the new record can be repositioned using the
Requery
method.
•
Example 16-8 adds a new book to the BOOKS table and makes it the current record. It
also demonstrates the
With...EndWith
construct.
Example 16-8. Adding a record with Recordset
Sub
exaRecordsetAddNew( )
Dim db As DATABASE
Dim rs As Recordset
Set db = CurrentDb
' Open recordset
Set rs = db.OpenRecordset("Books")
Debug.Print "Current title: " & rs!Title
' Use With...End With construct
With rs