English

How To: Add a row to an INFO file using VBA and ArcMap

Summary

This article shows how to create and populate a new row in an INFO table.

Procedure

  1. Open 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
    Note:
    Code in ThisDocument code module will only run in the current map document. To store the code in all map documents, open the code in the Normal.mxt ThisDocument code module.

  4. Paste the following code into the code module.

    Code:
    Sub AddRow()

    Dim pWorkspace As IWorkspaceFactory
    Set pWorkspace = New ArcInfoWorkspaceFactory
    Dim pFeatureWorkspace As IFeatureWorkspace
    Set pFeatureWorkspace = pWorkspace.OpenFromFile("c:\temp", 0)
    Dim pWorkspaceEdit As IWorkspaceEdit
    Set pWorkspaceEdit = pFeatureWorkspace
    Dim pTable As ITable
    Set pTable = pFeatureWorkspace.OpenTable("owner.dat")

    'Start an edit session
    pWorkspaceEdit.StartEditing True
    pWorkspaceEdit.StartEditOperation

    'Add the row
    Dim pRow As IRow
    Set pRow = pTable.CreateRow
    pRow.Value(1) = "Gilbert"
    pRow.Store

    'Stop the edit session
    pWorkspaceEdit.StopEditOperation
    pWorkspaceEdit.StopEditing True

    End Sub

  5. Modify the workspace path, INFO file name and values to be added.
  6. Close the Visual Basic Editor.
  7. Run the code.

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