HOW TO

Access a FeatureClass in a Personal GeoDatabase with IWorkspaceName

Last Published: April 25, 2020

Summary

Note:
This article pertains to ArcGIS versions 8.x and 9.x. Later versions of ArcGIS may contain different functionality, as well as different names and locations for menus, commands and geoprocessing tools.

Below is a sample of how to access a FeatureClass in a Personal geodatabase with the Name objects (IFeatureClassName).

Note: 
Support for Visual Basic for Applications (VBA) for ArcMap and ArcCatalog ended with the ArcGIS 10.2.2 release, and Esri has not included VBA compatibility setups since version 10.5. See: ArcGIS Desktop and VBA Moving Forward

Procedure

  1. Start ArcMap.
  2. Create a new UIButtonControl: How To: Create a new UIButtonControl​
Note:
For more information on creating a UIControl, see the ArcGIS Desktop Help topic: 'Creating custom commands with VBA and UI Controls'
  1. Right-click the UIButtonControl and select View Source.
  2. Copy the following code into the UIButtonControl's click event.
Public Sub OpenPersonalPGDBaseNameObjects()
   
''This is how to use the IWorkspaceName interface to get access to a FeatureClass in a
''PersonalGeodataBase

''Users should change the following 2 variables**************
    ''This is directory where the FeatureClass lives...
    Dim StrPathToDataBase As String
    StrPathToDataBase = "H:\2002_VB6_ArcObjects\data\Sample.mdb"
    
    ''This is the name of the ShapeFile...
    Dim StrFeatureClassName As String
    StrFeatureClassName = "testData"
''****************************************************
    ''This is the connection information that is used to access SDE...
    Dim ppropset As IPropertySet2
    Set ppropset = New PropertySet
   ppropset.SetProperty "DATABASE", StrPathToDataBase

    Dim pWorkSpaceName2 As IWorkspaceName2
    Set pWorkSpaceName2 = New WorkspaceName
     
    ''Notice this is a String. The ArcObjects help should have a listing of the
    ''other types (featureclass, tables, etc etc)
    pWorkSpaceName2.WorkspaceFactoryProgID = "esriCore.AccessWorkspaceFactory"
    pWorkSpaceName2.ConnectionProperties = ppropset
                
    Dim pname As IName
    Set pname = pWorkSpaceName2
    
    Dim pFeatureWorkspace As IFeatureWorkspace
    Set pFeatureWorkspace = pname.Open
    
    Dim pfeatureclass As IFeatureClass
    '''Look at the IFeatureWorkSpace as you can open Tables, DataSets, etc etc...
    '''Below we use IFeatureWorkSpace::OpenFeatureClass to get a FeatureClass...
    Set pfeatureclass = pFeatureWorkspace.OpenFeatureClass(StrFeatureClassName)
    
    ''Proving you have a featureclass...
    MsgBox pfeatureclass.FeatureCount(Nothing)
    
End Sub

Article ID:000005906

Software:
  • ArcMap 8 x
  • ArcMap 9 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic