Save edits VBA listener not working

231
1
12-09-2011 07:41 AM
JennyWallace
New Contributor
Hi,

I am trying to auto save edits using VBA in Arcmap 9.3.1 and can't get the listening events to work correctly.  When I start an edit session, i click on a button that begins listening, and my save procedure is triggered when the sketch is finished, but it only works for the first edit I make.  Obviously I am missing something with the listener, but cant figure it out.  Please help!

Jenny

Here is what I have:

Option Explicit
Private m_pEditor As IEditor
Private WithEvents EditorEvents As Editor
Private pEditLayers As IEditLayers

Private Sub startlistener_Click()
' This is a button that calls the start listening to edit events, this is probably
' a button you will want on your mxd

    StartListeningToEditEvents

End Sub

Private Function startlistener_ToolTip() As String
    startlistener_ToolTip = "startlistener"
End Function

Public Sub StartListeningToEditEvents()

'this sub actually starts the listener
    Set EditorEvents = Application.FindExtensionByName("ESRI Object Editor")
    MsgBox ("Listener is now Started")
End Sub

Private Sub EditorEvents_OnSketchFinished()
Dim pApp As IApplication
Dim pEditor As IEditor
Dim pID As New UID
pID = "esriCore.Editor"
Set pApp = Application
Set pEditor = pApp.FindExtensionByCLSID(pID)
Set pEditLayers = m_pEditor
Set EditorEvents = m_pEditor
'If pEditor.EditState = esriStateEditing Then
    If pEditor.HasEdits Then
            'pID = "esriCore.Editor"
            'Set m_pEditor = Application.FindExtensionByCLSID(pID)
            'Set m_pEditLayers = m_pEditor
            'Set EditorEvents = m_pEditor
            Dim pSaveEdits As ICommandItem
            pID.Value = "{59D2AFD2-9EA2-11D1-9165-0080C718DF97}"
            Set pSaveEdits = Application.Document.CommandBars.Find(pID)
            pSaveEdits.Execute

    End If
'End If
End Sub
0 Kudos
1 Reply
DuncanHornby
MVP Notable Contributor
Jenny,

The only thing I spotted with your code is this line:

Set EditorEvents = Application.FindExtensionByName("ESRI Object Editor")


All the code samples in help use:

Dim pID as New UID
pID = "esriEditor.Editor"
Set m_pEditor = Application.FindExtensionByCLSID(pID)
Set EditEvents = m_pEditor


Duncan
0 Kudos