Select to view content in your preferred language

open a file geodatabase from within access

3932
1
11-21-2011 02:06 PM
JoseLuis_Serrano
Occasional Contributor
Hi,

I have an access 2007 database with a form that adds tower information to several tables in that database. Since one of the attributes we add is the coordinates, we want to keep a feature layers for these towers in a separete file geodatabase and update it using the same form in the first access 2007 database.

Unfortunately, I get a run-time error / automation error when I try to open the file geodatabase from the access 2007 form. I have also tried with a personal geodatabase, but I got the same error.

Curiously, if I run the code from within ArcMap, it works like a charm.

I don't know if there is any restrictions on accessing the geoDatabase from outside an ArcMap Document or I am missing something else .

Thank you very much,
casti

' these are the libraries I have referenced
' ESRI GeoDatabase Object Library
' ESRI DataSourcesGDB OBJECT Library
' ESRI Geometry Object Library

Public Sub createFeatureFromXYCoordinates()
    ' Subtask 1. Access the States feature class.
    Dim pWSF As IWorkspaceFactory
    Dim pFWS As IFeatureWorkspace
    Dim pFC As IFeatureClass
    Set pWSF = New FileGDBWorkspaceFactory
    Set pFWS = pWSF.OpenFromFile("C:\feature_lyr_from_table_view_filegdb.gdb", 0) ' i got the error here
    Set pFC = pFWS.OpenFeatureClass("GIS_Info_Spatial")
    MsgBox "There are " & pFC.FeatureCount(Nothing) & " mets"
   
    ' Get coordinate system.
    Dim geoDataset As IGeoDataset
    Set geoDataset = pFC
    Dim gcs As IGeographicCoordinateSystem
    Set gcs = geoDataset.SpatialReference
   
    ' Create a new point using the gcs.
    Dim pPoint As IPoint
    Set pPoint = New Point
    Set pPoint.SpatialReference = gcs
    pPoint.PutCoords -121.35, 50.01
   
    ' Create a new feature.
    Dim feature As IFeature
    Set feature = pFC.CreateFeature
    Set feature.Shape = pPoint
    feature.Store
    MsgBox "Now there are " & pFC.FeatureCount(Nothing) & " mets"
End Sub
0 Kudos
1 Reply
JoseLuis_Serrano
Occasional Contributor
Hi,

after some workarounds we found out that you need to include some code to check the license first.
Just in case someone also needs it, this is the code that you have to add at the beginning:

Dim pAoInit As IAoInitialize
Set pAoInit = New AoInitialize
pAoInit.Initialize esriLicenseProductCodeArcView

Cheers,
casti
0 Kudos