Link to home
Start Free TrialLog in
Avatar of Jan Vojtech Vanicek
Jan Vojtech VanicekFlag for Czechia

asked on

For Each ... Next VB.NET 2010 and Outlook 2010 problem

Hi experts,
Im writting little application for recursive move content of outlook folders to another. Nothing difficult.

Im using VS 2010 (Visual Basic) and Office 2010. All fully patched.

My code is easy for example:

Private Sub WipeRecurse(RootFolder As Folder, DstFolder As Folder)
        Dim cnt As ContactItem

       For Each cnt in RootFolder.Items
            cnt.Move(DstFolder)
        Next


        Dim sf As Folder

        For Each sf in RootFolder.Folders
            WipeRecurse(sf, DstFolder)
        Loop

        If RootFolder.FolderPath <> ComboBox2.SelectedItem Then
            RootFolder.Delete()
        End If

    End Sub

Open in new window


Last contact or folder in each parent folder is not handled... Scary? please can you try it?

Is there any hotfix for that?

Following code is working as expected:

    Private Sub WipeRecurse(RootFolder As Folder, DstFolder As Folder)
        Dim cnt As ContactItem

        Do Until RootFolder.Items.Count = 0
            cnt = RootFolder.Items(RootFolder.Items.Count)
            cnt.Move(DstFolder)

        Loop


        Dim sf As Folder

        Do Until RootFolder.Folders.Count = 0
            sf = RootFolder.Folders.Item(RootFolder.Folders.Count)
            WipeRecurse(sf, DstFolder)
        Loop

        If RootFolder.FolderPath <> ComboBox2.SelectedItem Then
            RootFolder.Delete()
        End If

    End Sub

Open in new window

Avatar of Paul Jackson
Paul Jackson
Flag of United Kingdom of Great Britain and Northern Ireland image

Hmm interesting, try changing to as below to see if that makes any difference :

Private Sub WipeRecurse(RootFolder As Folder, DstFolder As Folder)

       For Each cnt As ContactItem in RootFolder.Items
            cnt.Move(DstFolder)
        Next

        For Each sf As Folder in RootFolder.Folders
            WipeRecurse(sf, DstFolder)
        Loop

        If RootFolder.FolderPath <> ComboBox2.SelectedItem Then
            RootFolder.Delete()
        End If

    End Sub 

Open in new window


If that doesn't solve it, when running through in debug can you examine the Items collection or the Folders collection returned and see if what you expect to be returned is returned by the collection.
ASKER CERTIFIED SOLUTION
Avatar of Jan Vojtech Vanicek
Jan Vojtech Vanicek
Flag of Czechia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jan Vojtech Vanicek

ASKER

Interops are simply crap...