Locked SyncObject.OnError does not fire

  • יום שני 18 יוני 2012 21:53
     
      קוד כלול

    I have a Visual Basic application in Visual Basic 2010 Express which interfaces with Outlook 2007. I want to use the SyncObject OnError event to detect an error while syncing but the event doesn't seem to fire. I get the Progress, SyncStart, and SyncEnd events but not the OnError event. The following code snippet illustrates what I'm trying to do.

    Imports Outlook = Microsoft.Office.Interop.Outlook
    Public Class Form1
        Public WithEvents olSync As Outlook.SyncObject
            Private Sub ButtonSync_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonSync.Click
            Dim olApp As Outlook.Application
            Dim olNS As Outlook.NameSpace
            olApp = CreateObject("Outlook.Application")
            olNS = olApp.GetNamespace("MAPI")
            olSync = olNS.SyncObjects.Item("All Accounts")
            olSync.Start()
        End Sub
        Private Sub olSync_OnError(ByVal Code As Integer, ByVal Description As String) Handles olSync.OnError
            Debug.Print("SyncError Event Fired")
        End Sub
        Private Sub olSync_Progress(ByVal State As Microsoft.Office.Interop.Outlook.OlSyncState, ByVal Description As String, ByVal Value As Integer, ByVal Max As Integer) Handles olSync.Progress
            Debug.Print("Progress Event Fired")
        End Sub
        Private Sub olSync_SyncEnd() Handles olSync.SyncEnd
            Debug.Print("SyncEnd Event Fired")
        End Sub
        Private Sub olSync_SyncStart() Handles olSync.SyncStart
            Debug.Print("SyncStart Event Fired")
        End Sub
    End Class

    In the immediate window I can see the start, end, and progress events fire, but not the error event. I can confirm there is an error by lookin in the Outlook Send/Receive Progress window, and that it says error in the status bar at the bottom of Outlook. Stranger still, if I put the code above in a VBA module within Outlook, all four events fire! What can I do to make sure I see the OnError event from my Visual Basic application?

כל התגובות

  • יום רביעי 20 יוני 2012 06:43
    מנחה דיון
     
     

    Hi Jason,

    Welcome to the MSDN forum.

    You can add a break point on method olSync_OnError to monitor whether it had been called. Moreover, the first parameter 'code' in this method, its type should be long not integer. 

    Best regards,


    Shanks Zen
    MSDN Community Support | Feedback to us

  • יום שישי 22 יוני 2012 16:24
     
     
    I changed the type for the code parameter to long and still no luck. Whether or not I use a break point to monitor the event or rely on the text output, the OnError event does not fire. Any other suggestions?