HOW TO
This article shows how to create and populate a new row in a personal geodatabase table.
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.
Code:
Sub AddRow()
Dim pPropset As IPropertySet
Set pPropset = New PropertySet
pPropset.SetProperty "DATABASE", "C:\Country.mdb"
pPropset.SetProperty "DATAPROVIDER", "Access Data Source"
Dim pwf As IWorkspaceFactory
Set pwf = New AccessWorkspaceFactory
Dim fws As IFeatureWorkspace
Set fws = pwf.Open(pPropset, 0)
'Open the Table
Dim ptable As ITable
Set ptable = fws.OpenTable("Names")
'Create new row
Dim pCursor As ICursor
Dim arow As IRow
Dim pRowBuff As IRowBuffer
Set pRowBuff = ptable.CreateRowBuffer
'Populate the row with values
pRowBuff.Value(1) = 100 'Numeric column
pRowBuff.Value(2) = "Canada" 'Text column
Set pCursor = ptable.Insert(True)
pCursor.InsertRow pRowBuff
End Sub
Get help from ArcGIS experts
Download the Esri Support App