none
MoveToFolder launched via inspector does not trigger an BeforeItemMove event RRS feed

  • Question

  • I use the BeforeItemMove event to keep track of the new Folder after moving an item in my VBA program. This works well if I launch:

       Application.ActiveExplorer.CommandBars.ExecuteMso "MoveToFolder"

    but the event is not triggered after using:

       Application.ActiveInspector.CommandBars.ExecuteMso "MoveToFolder"

    I have made the following test program to demonstrate (this runs in ThisOutlookSession), listed below. The TestmyItem subroutine gives a message to select MoveToFolder via Explorer or Inspector. When the BeforeItemMove event is triggered, another messagebox will appear. Selecting the move via the Explorer will trigger the event, via the Inspector not.

    I do need to move one item in a selection, so want to use the inspector method (instead of using the explorer method, which will move the whole selection). Any help is appreciated....

    Public Sub TestmyItem()
        Dim currentExplorer As Explorer
        Dim currentSelection As Selection
        Dim currentItem As Object
        Dim currentMailItem As MailItem
        Dim currentFolder As Outlook.folder
        Dim msgResult As Integer
        
        Set currentSelection = Application.ActiveExplorer.Selection
        
        If MsgBox("Use Explorer (yes) or Inspector (no) move", vbYesNo, "Select move method") = vbYes Then
        
            Set currentItem = currentSelection.Item(1)
            If currentItem.Class = olMail Then
                Set currentMailItem = currentItem
                Set myItem = currentMailItem
                Set myFolder = currentMailItem.Parent
        
                Application.ActiveExplorer.CommandBars.ExecuteMso "MoveToFolder"
            
            End If
        
        Else
        
            For Each currentItem In currentSelection
                If currentItem.Class = olMail Then
                    Set currentMailItem = currentItem
                    Set myItem = currentMailItem
                    Set myFolder = currentMailItem.Parent
                
                    currentMailItem.Display
                    currentMailItem.UnRead = True
                    Application.ActiveInspector.CommandBars.ExecuteMso "MoveToFolder"
                
                End If
            Next
            
        End If

        Set myItem = Nothing
        Set myFolder = Nothing

    End Sub


    Public Sub myFolder_BeforeItemMove(ByVal Item As Object, ByVal MoveTo As MAPIFolder, Cancel As Boolean)
        MsgBox "this is BeforeItemMove; myItem: " & myItem.EntryID & "; myFolder: " & myFolder.FolderPath
        Cancel = False
        Set myItem = Nothing
        Set myFolder = Nothing
    End Sub

    Wednesday, May 29, 2013 2:21 AM

Answers

  • I can verify the problem here on Outlook 2010, I haven't tried it in 2013. It also occurs if currentMailItem.GetInspector is used instead of ActiveInspector.
     
    As a workaround, try using the MailItem.Move() method. Before using that, which requires a target folder obect use the NameSpace.PickFolder() method to get the selected folder.
     
    If you have an MSDN account you might want to file a support case on this.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Jan_Grotenbreg" <=?utf-8?B?SmFuX0dyb3RlbmJyZWc=?=> wrote in message news:6731101a-eb3f-4fa0-8fb5-db9fc0bb6bac...

    I use the BeforeItemMove event to keep track of the new Folder after moving an item in my VBA program. This works well if I launch:

       Application.ActiveExplorer.CommandBars.ExecuteMso "MoveToFolder"

    but the event is not triggered after using:

       Application.ActiveInspector.CommandBars.ExecuteMso "MoveToFolder"

    I have made the following test program to demonstrate (this runs in ThisOutlookSession), listed below. The TestmyItem subroutine gives a message to select MoveToFolder via Explorer or Inspector. When the BeforeItemMove event is triggered, another messagebox will appear. Selecting the move via the Explorer will trigger the event, via the Inspector not.

    I do need to move one item in a selection, so want to use the inspector method (instead of using the explorer method, which will move the whole selection). Any help is appreciated....

    Public Sub TestmyItem()
        Dim currentExplorer As Explorer
        Dim currentSelection As Selection
        Dim currentItem As Object
        Dim currentMailItem As MailItem
        Dim currentFolder As Outlook.folder
        Dim msgResult As Integer
        
        Set currentSelection = Application.ActiveExplorer.Selection
        
        If MsgBox("Use Explorer (yes) or Inspector (no) move", vbYesNo, "Select move method") = vbYes Then
        
            Set currentItem = currentSelection.Item(1)
            If currentItem.Class = olMail Then
                Set currentMailItem = currentItem
                Set myItem = currentMailItem
                Set myFolder = currentMailItem.Parent
        
                Application.ActiveExplorer.CommandBars.ExecuteMso "MoveToFolder"
            
            End If
        
        Else
        
            For Each currentItem In currentSelection
                If currentItem.Class = olMail Then
                    Set currentMailItem = currentItem
                    Set myItem = currentMailItem
                    Set myFolder = currentMailItem.Parent
                
                    currentMailItem.Display
                    currentMailItem.UnRead = True
                    Application.ActiveInspector.CommandBars.ExecuteMso "MoveToFolder"
                
                End If
            Next
            
        End If

        Set myItem = Nothing
        Set myFolder = Nothing

    End Sub


    Public Sub myFolder_BeforeItemMove(ByVal Item As Object, ByVal MoveTo As MAPIFolder, Cancel As Boolean)
        MsgBox "this is BeforeItemMove; myItem: " & myItem.EntryID & "; myFolder: " & myFolder.FolderPath
        Cancel = False
        Set myItem = Nothing
        Set myFolder = Nothing
    End Sub


    Ken Slovak MVP - Outlook
    Wednesday, May 29, 2013 2:59 PM
    Moderator

All replies

  • I can verify the problem here on Outlook 2010, I haven't tried it in 2013. It also occurs if currentMailItem.GetInspector is used instead of ActiveInspector.
     
    As a workaround, try using the MailItem.Move() method. Before using that, which requires a target folder obect use the NameSpace.PickFolder() method to get the selected folder.
     
    If you have an MSDN account you might want to file a support case on this.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Jan_Grotenbreg" <=?utf-8?B?SmFuX0dyb3RlbmJyZWc=?=> wrote in message news:6731101a-eb3f-4fa0-8fb5-db9fc0bb6bac...

    I use the BeforeItemMove event to keep track of the new Folder after moving an item in my VBA program. This works well if I launch:

       Application.ActiveExplorer.CommandBars.ExecuteMso "MoveToFolder"

    but the event is not triggered after using:

       Application.ActiveInspector.CommandBars.ExecuteMso "MoveToFolder"

    I have made the following test program to demonstrate (this runs in ThisOutlookSession), listed below. The TestmyItem subroutine gives a message to select MoveToFolder via Explorer or Inspector. When the BeforeItemMove event is triggered, another messagebox will appear. Selecting the move via the Explorer will trigger the event, via the Inspector not.

    I do need to move one item in a selection, so want to use the inspector method (instead of using the explorer method, which will move the whole selection). Any help is appreciated....

    Public Sub TestmyItem()
        Dim currentExplorer As Explorer
        Dim currentSelection As Selection
        Dim currentItem As Object
        Dim currentMailItem As MailItem
        Dim currentFolder As Outlook.folder
        Dim msgResult As Integer
        
        Set currentSelection = Application.ActiveExplorer.Selection
        
        If MsgBox("Use Explorer (yes) or Inspector (no) move", vbYesNo, "Select move method") = vbYes Then
        
            Set currentItem = currentSelection.Item(1)
            If currentItem.Class = olMail Then
                Set currentMailItem = currentItem
                Set myItem = currentMailItem
                Set myFolder = currentMailItem.Parent
        
                Application.ActiveExplorer.CommandBars.ExecuteMso "MoveToFolder"
            
            End If
        
        Else
        
            For Each currentItem In currentSelection
                If currentItem.Class = olMail Then
                    Set currentMailItem = currentItem
                    Set myItem = currentMailItem
                    Set myFolder = currentMailItem.Parent
                
                    currentMailItem.Display
                    currentMailItem.UnRead = True
                    Application.ActiveInspector.CommandBars.ExecuteMso "MoveToFolder"
                
                End If
            Next
            
        End If

        Set myItem = Nothing
        Set myFolder = Nothing

    End Sub


    Public Sub myFolder_BeforeItemMove(ByVal Item As Object, ByVal MoveTo As MAPIFolder, Cancel As Boolean)
        MsgBox "this is BeforeItemMove; myItem: " & myItem.EntryID & "; myFolder: " & myFolder.FolderPath
        Cancel = False
        Set myItem = Nothing
        Set myFolder = Nothing
    End Sub


    Ken Slovak MVP - Outlook
    Wednesday, May 29, 2013 2:59 PM
    Moderator
  • Thanks for the answer, this helped to make a workaround. FYI I run this on Outlook 2013.

    I am occasionally developing subroutines in Outlook and Excel, to speed up my tasks, so I dont have a MSDN account.

    Best Regards, Jan

    Wednesday, May 29, 2013 9:33 PM
  • I filed a bug for this with the Outlook product group. I haven't heard back from them on it yet. I can't guarantee that it will be fixed in a hot fix or service pack, or even if it's ever fixed. But at least it's in the system now.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Jan_Grotenbreg" <=?utf-8?B?SmFuX0dyb3RlbmJyZWc=?=> wrote in message news:1d07bbfa-1770-4093-916c-5406e26f9278...

    Thanks for the answer, this helped to make a workaround. FYI I run this on Outlook 2013.

    I am occasionally developing subroutines in Outlook and Excel, to speed up my tasks, so I dont have a MSDN account.

    Best Regards, Jan


    Ken Slovak MVP - Outlook
    Friday, May 31, 2013 7:17 PM
    Moderator