Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    314
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Move method diffculties (Office 2000 Sr1a)

    I have used the restrict method on the inbox to create a collection of mail items called olNewItems.
    I then use this code to move them to a new folder called fldDest

    For Each olMsg In olNewItems


    olMsg.Move fldDest
    Next olMsg

    Although it moves the first item in the collection successfully, it does not loop through the collection. Has anyone come accross this?
    I can't find anything at the MS KB that throws light on this method not working.
    If I replace it with:

    For Each olMsg In olNewItems

    olMsg.Display

    Next olMsg


    it DOES loop. So the Move method is interfering somehow.
    Has anyone had this problem?
    Any ideas much appreciated.

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Move method diffculties (Office 2000 Sr1a)

    One possibility is that you are changing the collection you are iterating over by moving one of its members.

    The most common way to solve this with object collections in Word, with which I am more familiar, is to use a numeric index and count backwards:

    For intCounter = olNewItems.Count To 1 Step -1
    olNewItems(intCounter).Move
    Next 'intCounter

    Will this work in this context? You'll have to try it and let us know.

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    314
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Move method diffculties (Office 2000 Sr1a)

    I think you're right about the collection becoming unrecognisable to itself because I've moved on of its objects.
    But this code is used as a example quite often in the help files and on Microsoft's KB website as THE way to move mail items. Here's one quote from the help files (see below)
    So I am a trifle discombobulated!
    I will look into your idea though.

    Set myNameSpace = Application.GetNameSpace("MAPI")
    Set myFolder = myNameSpace.GetDefaultFolder(6)
    Set myItems = myFolder.Items
    Set myRestrictItems = myItems.Restrict _
    ("[Categories] = 'Project X'")
    For Each myItem In myRestrictItems
    myItem.Move myFolder.Folders("Project X")
    Next

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •