English

How To: Add a non-geodatabase Access table to ArcMap

Summary

This article shows how to add a non-geodatabase Access table to ArcMap using VBA and ArcObjects.

Procedure

  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
    Note:
    Code in 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.

    Code:
    Sub AddTable()
    ' Get the table from the workspace factory
    Dim pWf As IWorkspaceFactory
    Set pWf = New AccessWorkspaceFactory
    Dim pWs As IFeatureWorkspace
    Set pWs = pWf.OpenFromFile("c:\incidents\February\DF\db2.mdb", 0)
    Dim pTable As ITable
    Set pTable = pWs.OpenTable("Dogs")

    ' Get a Standalone Table
    Dim pStTable As IStandaloneTable
    Set pStTable = New StandaloneTable
    Set pStTable.Table = pTable

    ' Add the table to ArcMap
    Dim pDoc As IMxDocument
    Set pDoc = ThisDocument
    Dim pMap As IMap
    Set pMap = pDoc.FocusMap
    Dim pTc As IStandaloneTableCollection
    Set pTc = pMap
    pTc.AddStandaloneTable pStTable

    ' Refresh the View and Table of Contents
    pDoc.ActiveView.Refresh
    pDoc.UpdateContents
    End Sub

  5. Close the Visual Basic Editor.
  6. Run the code.

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