Table of contents
Collapse the table of content
Expand the table of content

Adding Records Using AddNew

office 365 dev account|Last Updated: 6/12/2017
1 Contributor

Applies to: Access 2013 | Access 2016

This is the basic syntax of the AddNew method:


The FieldList and Values arguments are optional. FieldList is either a single name or an array of names or ordinal positions of the fields in the new record. The Values argument is either a single value or an array of values for the fields in the new record. Typically, when you intend to add a single record, you will call the AddNew method without any arguments. Specifically, you will call AddNew, set the Value of each field in the new record, and then call Update and/or UpdateBatch. You can ensure that your Recordset supports adding new records by using the Supports property with the adAddNew enumerated constant. The following code uses this technique to add a new Shipper to the sample Recordset. The ShipperID field value is supplied automatically by SQL Server, so the code does not attempt to supply a field value for the new records.

 If objRs1.Supports(adAddNew) Then 
 With objRs1 
 .Fields("CompanyName") = "Sample Shipper" 
 .Fields("Phone") = "(931) 555-6334" 
 End With 
 End If 

Because this code uses a disconnected Recordset with a client-side cursor in batch mode, you must reconnect the Recordset to the data source with a new Connection object before you can call the UpdateBatch method to post changes to the database. This is easily done by using the new function GetNewConnection.

 'Re-establish a Connection and update 
 Set objRs1.ActiveConnection = GetNewConnection 

Access for developers forum on MSDN
Access help on
Access help on
Search for specific Access error codes on Bing
Access forums on UtterAccess
Access wiki on UtterAcess
Access developer and VBA programming help center (FMS)
Access posts on StackOverflow

© 2018 Microsoft