I am writing an application that takes data from an Excel Spreadsheet and loads it into an ArcSDE feature class. The Feature class is editable within ArcMap, but I am having trouble inserting a feature with the code.
My code does the following
Starts an edit session.
Public Sub StartEditing(fctarget) Dim peditor As IEditor Dim pID As New UID Dim pFeatureLayer As IFeatureLayer Dim pDataset As IDataset Dim pMap As IMap Dim pmxdoc As IMxDocument Dim LayerCount As Integer Set pmxdoc = Application.Document Set pMap = pmxdoc.FocusMap pID = "esriEditor.Editor" Set peditor = Application.FindExtensionByCLSID(pID) If peditor.EditState = esriStateEditing Then Exit Sub 'Start editing the workspace of teh feature layer Set pDataset = fctarget MsgBox "Editing: " & pDataset.BrowseName peditor.StartEditing pDataset.Workspace peditor.StartOperation End Sub
Load the data (if it is a new record, the following code runs)
If pfeatLayer Is Nothing Then 'if it does not exist - it is new 'Insert a new record and add new attribute information Set pFeatInsertBuf.Shape = pFeat.Shape Debug.Print pFeatInsertBuf.Shape.envelope.XMax xField = pFeatInsertBuf.Fields.FindFieldByAliasName("ORIG_X") yField = pFeatInsertBuf.Fields.FindFieldByAliasName("ORIG_Y") pFeatInsertBuf.Value(xField) = pFeat.extent.XMax pFeatInsertBuf.Value(yField) = pFeat.extent.YMax 'Update the attributes For C = 1 To NumberOfFields If IsNull(pExcelApp.Cells(r, C).Value) Then pFeatInsertBuf.Value(C).Value = "" Else pFeatInsertBuf.Value(C) = pExcelApp.Cells(r, C).Value End If Next C Debug.Print pFeatInsertBuf.Fields.FieldCount Debug.Print pFeatInsertBuf.Value(2) Debug.Print pFeatInsertCur.Fields.FieldCount 'store the record pFeatInsertCur.InsertFeature pFeatInsertBuf ' #######INSERT THE FEATURE###### Print #1, "Row number " & r & ": " & "inserted" Debug.Print "Row number " & r & ": " & "inserted"
When it has gone through the rest of the spreadsheet, the stop editing process is called and the editor session is closed.
Public Sub stopSaveEdits(step As String) Dim lngCityDevRefVal As Long Dim peditor As IEditor Dim pID As New UID Dim lngSave As Integer Dim pMap As IMap Dim pmxdoc As IMxDocument ' get the current map document and create and editor object Set pmxdoc = ThisDocument Set pMap = pmxdoc.FocusMap pID = "esriEditor.Editor" Set peditor = Application.FindExtensionByCLSID(pID) 'step = "Save" If peditor.EditState = esriStateEditing Then 'lngSave = MsgBox("Do you want to save?", vbYesNo, "Save data") If step = "Save" Then peditor.StopOperation "Saving..." Exit Sub ElseIf step = "SaveStop" Then peditor.StopOperation "Saving..." If peditor.HasEdits = True Then peditor.StopEditing True 'MsgBox "Changes have been saved" Exit Sub End If Else peditor.AbortOperation 'peditor.StopOperation "Saving..." peditor.StopEditing False MsgBox "Changes have not been saved" End If End If End Sub
The problem is that the new feature never gets inserted, even though i have specified to do it. Has anyone got any ideas on what I am doing wrong?
Note - Using ArcGIS Desktop 9.3.1, ArcSDE is 9.2
Thanks!