jtodd83

Save edits VBA listener not working

Discussion created by jtodd83 on Dec 9, 2011
Latest reply on Dec 10, 2011 by Hornbydd
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

Outcomes