Skip to content

Latest commit

 

History

History
38 lines (34 loc) · 1.36 KB

File metadata and controls

38 lines (34 loc) · 1.36 KB
title Adding Multiple Fields | Microsoft Docs
ms.prod sql
ms.prod_service connectivity
ms.technology connectivity
ms.custom
ms.date 01/19/2017
ms.reviewer
ms.topic conceptual
helpviewer_keywords
AddNew method [ADO]
ADO, adding data
editing data [ADO], adding multiple fields
editing data [ADO], AddNew method
ms.assetid f3648ef4-9f36-4991-a868-83a617389844
author MightyPen
ms.author genemi

Adding Multiple Fields and Values

Occasionally, it might be more efficient to pass in an array of fields and their corresponding values to the AddNew method, rather than setting Value multiple times for each new field. If FieldList 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 following code passes an array of fields and an array of values to the AddNew method.

'BeginAddNew2
    Dim avarFldNames As Variant
    Dim avarFldValues As Variant

    avarFldNames = Array("CompanyName", "Phone")
    avarFldValues = Array("Sample Shipper 2", "(931) 555-6334")

    If objRs1.Supports(adAddNew) Then
        objRs1.AddNew avarFldNames, avarFldValues
    End If

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