Use ITable:UpdateSearchedRows to update the selected rows

Last Published: April 25, 2020


This article shows how to use ITable:UpdateSearchedRows to update the rows selected by a Query Filter.


  1. Start ArcMap.
  2. Open the Visual Basic Editor.

    In ArcMap, select Tools > Macros > Visual Basic Editor.

  3. In the Project Explorer window, expand Project.mxt and select ArcMap Objects > ThisDocument. Right-click and select View Code.
    [O-Image] Visual Basic Project  Explorer
    Code in the ThisDocument module will only run in the current map document. To store the code in all your map documents, open the Normal.mxt ThisDocument code module.

  4. Copy the following into the code module.

    Sub ChangeRows()
    Dim pTC As ITableCollection
    Dim pTable As ITable
    Dim pMap As IMap
    Dim pDoc As IMxDocument
    Dim pRow As IRow
    Dim pQF As IQueryFilter
    Dim pRowBuff As IRowBuffer

    'Get the first table from the map
    Set pDoc = ThisDocument
    Set pMap = pDoc.FocusMap
    Set pTC = pMap
    Set pTable = pTC.Table(0)

    'Create a query filter to select rows
    'to be updated
    Set pQF = New QueryFilter
    pQF.WhereClause = "TRACT_ID < 400"

    'Create the row buffer and set the value for the field to update
    Set pRowBuff = pTable.CreateRowBuffer
    pRowBuff.Value(pTable.FindField("Edited")) = "Done"
    'Update the rows
    pTable.UpdateSearchedRows pQF, pRowBuff
    End Sub

  5. Close the Visual Basic Editor.
  6. Add a table to ArcMap and modify code to fit your data.
  7. Run the code.

    A. Click Tools > Macros > Macros to display the Macros dialog box.
    B. Select a macro and click Run.

Article ID:000001933

  • ArcMap 8 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic