HOW TO
Instructions provided describe how to export selected rows from a stand-alone table to a new stand-alone table using ArcObjects.
Note:
Code in the Project's ThisDocument code module will only run in the current map document. To store the code in all the map documents, open the Normal.mxt ThisDocument code module instead.
Code:
Sub ExportSelectedRowsTable()
' get table collection of focus data frame
' make reference to the top table in TOC
Dim pMxDoc As IMxDocument
Set pMxDoc = Application.Document
Dim pMap As IStandaloneTableCollection
Set pMap = pMxDoc.FocusMap
Dim pStdAloneTbl As IStandaloneTable
Set pStdAloneTbl = pMap.StandaloneTable(0)
'Get the Table Name and pass it to Dataset Name
Dim pTable As ITable
Set pTable = pStdAloneTbl.Table
Dim pDataset As IDataset
Set pDataset = pTable
Dim pInTableName As ITableName
Set pInTableName = pDataset.FullName
Dim pInDsName As IDatasetName
Set pInDsName = pInTableName
' get selection set from table
Dim pTableSel As ITableSelection
Set pTableSel = pStdAloneTbl
Dim pSelSet As ISelectionSet
Set pSelSet = pTableSel.SelectionSet
' create a new output table name and pass it to dataset name
Dim pOutTableName As ITableName
Set pOutTableName = New TableName
Dim pOutDSName As IDatasetName
Set pOutDSName = pOutTableName
pOutDSName.Name = "TestExport.dbf" ' Define the name
' specify output workspace and pass it to Output Dataset Name
Dim pWorkspaceName As IWorkspaceName
Set pWorkspaceName = New WorkspaceName
pWorkspaceName.PathName = "c:\temp"
pWorkspaceName.WorkspaceFactoryProgID = "esriCore.shapefileworkspacefactory.1"
Set pOutDSName.WorkspaceName = pWorkspaceName
' export table
Dim pExportOp As IExportOperation
Set pExportOp = New ExportOperation
pExportOp.ExportTable pInDsName, Nothing, pSelSet, pOutDSName, 0
End Sub
Article ID:000008745
Get help from ArcGIS experts
Download the Esri Support App