Open a DBF Table

Created:9/23/2002
Description:

This sample shows how to open a DBF table.

How to use:
  1. Copy the OpenTable subroutine into the VBA editor of an opened map document.
  2. Change the "filePath" and "tableName" accordingly.
  3. Execute the subroutine.
Public Sub OpenTable()
  Dim filePath As String
  filePath = "D:\arcgis\arcexe83\ArcObjects Developer Kit\samples\data\USA"
  Dim tableName As String
  tableName = "states.dbf"
  
  Dim pMxDoc As IMxDocument
  Set pMxDoc = ThisDocument
    
  Dim pWorkspace As IWorkspace
  Dim pFact As IWorkspaceFactory
  Set pFact = New ShapefileWorkspaceFactory
    
  Set pWorkspace = pFact.OpenFromFile(filePath, 0)
  Dim pFWorkspace As IFeatureWorkspace
  Set pFWorkspace = pWorkspace
  
  Dim pTable As ITable
  Set pTable = pFWorkspace.OpenTable(tableName)
  'use the table accordingly
  MsgBox "Total rows of the table: " & pTable.RowCount(Nothing)
End Sub