none
Recognizing Outlook Sync is over RRS feed

  • Question

  • Hey guys.

    I'm trying to automate an outlook flow but can't seem to recognize when all folders are synchronized.

    As far as I could tell, the Outlook status bar is made of one class (NetUIHWND) so I can't read its notifications ("All folders are up to date...").

    Do any of you know how one can check if sync is over as simply as possible?

    Sorry if I wasn't clear or wasn't following the forum protocol. It's my first ever real programming assignment and first ever forum entry.

    Thanx a lot,

    Mickey

    Monday, May 7, 2012 7:11 AM

Answers

  • One way is to work with a SyncObject, which is analagous to an entry in the Send/Receive groups.  Here's a VBA example (create an instance of the class in another module to start it):

    Option Explicit
    Dim WithEvents mySyncObject  As SyncObject
    Dim mySyncObjects As SyncObjects
    
    Private Sub Class_Initialize()
        Dim objNS As Outlook.NameSpace
        Dim intX As Integer
        
        Set objNS = Application.GetNamespace("MAPI")
        Set mySyncObjects = objNS.SyncObjects
        
        For intX = 1 To mySyncObjects.Count
            Debug.Print mySyncObjects.Item(intX).Name
        Next
        
        'Set a hard reference to the first send/receive group (usually 'All Accounts')
        Set mySyncObject = mySyncObjects.Item(1)
    End Sub
    
    Private Sub mySyncObject_OnError(ByVal Code As Long, ByVal Description As String)
        Debug.Print "Sync error " & Code & ": '" & Description & "'"
    End Sub
    
    Private Sub mySyncObject_Progress(ByVal State As OlSyncState, ByVal Description As String, ByVal Value As Long, ByVal Max As Long)
        Debug.Print "Progress: " & Description & " (state = " & State & ")"
    End Sub
    
    Private Sub mySyncObject_SyncEnd()
        Debug.Print "Sync has ended for '" & mySyncObject.Name & "'"
    End Sub
    
    Private Sub mySyncObject_SyncStart()
        'Will fire as per the defined schedule for the group ("Schedule an automatic send/receive every x minutes")
        Debug.Print "Sync has started for '" & mySyncObject.Name & "'"
    End Sub
    
    However, Exchange Mailboxes can retrieve messages outside of any defined schedule in Send/Receive because it is constantly polling the server.  To hook into Exchange ICS (Incremental Change Synchronization), you need to work with Redemption - see RDOFolderSynchronizer.

    Eric Legault
    MVP (Outlook)
    About me...

    • Marked as answer by M. Friedmann Thursday, May 10, 2012 5:34 PM
    Monday, May 7, 2012 2:47 PM
    Moderator

All replies

  • One way is to work with a SyncObject, which is analagous to an entry in the Send/Receive groups.  Here's a VBA example (create an instance of the class in another module to start it):

    Option Explicit
    Dim WithEvents mySyncObject  As SyncObject
    Dim mySyncObjects As SyncObjects
    
    Private Sub Class_Initialize()
        Dim objNS As Outlook.NameSpace
        Dim intX As Integer
        
        Set objNS = Application.GetNamespace("MAPI")
        Set mySyncObjects = objNS.SyncObjects
        
        For intX = 1 To mySyncObjects.Count
            Debug.Print mySyncObjects.Item(intX).Name
        Next
        
        'Set a hard reference to the first send/receive group (usually 'All Accounts')
        Set mySyncObject = mySyncObjects.Item(1)
    End Sub
    
    Private Sub mySyncObject_OnError(ByVal Code As Long, ByVal Description As String)
        Debug.Print "Sync error " & Code & ": '" & Description & "'"
    End Sub
    
    Private Sub mySyncObject_Progress(ByVal State As OlSyncState, ByVal Description As String, ByVal Value As Long, ByVal Max As Long)
        Debug.Print "Progress: " & Description & " (state = " & State & ")"
    End Sub
    
    Private Sub mySyncObject_SyncEnd()
        Debug.Print "Sync has ended for '" & mySyncObject.Name & "'"
    End Sub
    
    Private Sub mySyncObject_SyncStart()
        'Will fire as per the defined schedule for the group ("Schedule an automatic send/receive every x minutes")
        Debug.Print "Sync has started for '" & mySyncObject.Name & "'"
    End Sub
    
    However, Exchange Mailboxes can retrieve messages outside of any defined schedule in Send/Receive because it is constantly polling the server.  To hook into Exchange ICS (Incremental Change Synchronization), you need to work with Redemption - see RDOFolderSynchronizer.

    Eric Legault
    MVP (Outlook)
    About me...

    • Marked as answer by M. Friedmann Thursday, May 10, 2012 5:34 PM
    Monday, May 7, 2012 2:47 PM
    Moderator
  • Thanx Eric.

    We've taken a different approach eventually.

    Have a great day!

    M.

    Thursday, May 10, 2012 5:34 PM