Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move item script in Outlook problem.

Status
Not open for further replies.

whloo

Programmer
Apr 14, 2003
168
SG
Hi,

I am facing a very weird problem.
Below is my code.
My intention is to process and move all the mails in my inbox to another folder.
My code work perfectly fine before i putting in my move item function.
It able to process all the msg without fails in inbox until i put in the move function.
After the move function in, it seems like it only return me partial of the inbox item :(

******************************************
Dim ol As Outlook.Application
Set ol = CreateObject("Outlook.Application")
Dim fd As Outlook.MAPIFolder

Dim ns As Outlook.NameSpace
Dim itms As Outlook.Items
Dim itm As Object

'Get to the current session of Outlook
Set ns = ol.GetNamespace("MAPI")

'Retrieve a collection of mail messages in the Inbox
Set itms = ns.GetDefaultFolder(olFolderInbox).Items

For Each itm In itms
' i use this read flag to test if it did return me all the items in inbox.
itm.UnRead = False

' 2 = the mailbox index, 7 = movefolder index
' if i disable/remove this code, all items in inbox will be marked as read, but if i enable the code below. only some of the code will be moved and marked as read.
itm.Move (ns.Folders(2).Folders(7))
Next

******************************************
 
Usually with these sort of problems your itms Collection is reducing in size as you move Items. Try getting the itms.Count property and use that to loop through the collection, but do it from the end, not the beginning. Something like (NOT TESTED)

a = itms.Count
For b = a to 1 Step - 1
itms(b).Unread = False
itms(b).Move (ns.Folders(2).Folders(7))
Next

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top