How to Write Feature Class data to a Personal Geodatabase

12-08-2011 01:20 AM
New Contributor
In ArcView 9.2 I am trying to set up a UIButtonControl containing VBA code to a)create a new personal GDB b)then write feature data (previously brought into ArcMap) to this new GDB. When I open ArcMap with some features(polylines,points,polygons) I want to be able to hit this UIButtoncontrol and create/populate a PGDB.

Although it runs outside of ArcView, there is a sample VBA project in the ArcGIS Developer Kit for 9.2 called Create_and_load_personal_geodatabaseVisualBasic, which appears to do 80 percent of what I need. Using various ArcObjects interfaces, it creates sample points,polygons,polylines etc. However there is no explanatory documentation, it doesn't work properly and before I took out some 'progress' controls this sample Developer Kit sample project wouldn't even compile. I've got it to create an empty PGDB and then it gives an automation error on trying to open:

  Dim pProperty As IpropertySet
  Set pProperty = New PropertySet
  Dim pWorkspaceName As IName
  On Error GoTo Duplicate
  Set pWorkspaceName = pWorkspaceFactory.Create(App.Path, databaseName, pProperty, 0)
  Set pWorkspace = pWorkspaceName.Open
  Exit Sub
  MsgBox "Database already exists.", vbExclamation + vbOKOnly, "Duplicate Database"

On Googleing the issue I literally get one reference, to the sample code itself.

Can anyone help with this problem, and is there a tutorial anywhere which takes you through each step for writing feature classes to a PGDB in VBA?
0 Kudos
2 Replies
MVP Frequent Contributor

You could get into using the GeoProcessor and calling existing tools through the Execute method, this avoids having to know every nuance of ArcObjects.

If you want to use the ArcObjects approach then in VBA all you need to do to create a PERSONAL geodatabase is this:

Public Sub test()
    Dim pWSF As IWorkspaceFactory
    Set pWSF = New AccessWorkspaceFactory
    Dim pWSN As IWorkspaceName
    Set pWSN = pWSF.Create("C:\temp", "pGDB_Test", Nothing, 0)
End Sub

0 Kudos
New Contributor
Dear all,

I am having the same problem.
I tried sample codes to open a File GDB Workspace which already exists with the name testGDB.gdb:
there is also a sample in EDN, I have ArcGIS 10, Visualstudio 2008.
I always get NULL result for the variable "outWorkspace", that is why I cant get any pointer to create a feature class inside the GDB.
Is there something I am missing !? any hint !????
I have checked several times, there is no problem with my path ! because the testGDB.gdb is created directly by ArcGIS
connString is in my case : C:\Daten\Bearbeitung\testGDB.gdb which goes with the codes.

HRESULT openFGDBWorkspace(BSTR connString, IWorkspace** outWorkspace)
IWorkspaceFactoryPtr ipWorkspaceFactory(CLSID_FileGDBWorkspaceFactory);
return ipWorkspaceFactory->OpenFromFile(connString, NULL, outWorkspace);
I tried also to go through IWorkspaceName, IName.Open() gives also NULL result ! am I missing a kind of Initializing the Licence ??? It is a Desktop Product !
thanks for any help.
0 Kudos