Items Collection Not Sorting Folder - (Outlook 2000 Standalone)

  • Thread starter Thread starter Jed_Klampett
  • Start date Start date
J

Jed_Klampett

I have duplicate messages in a folder called "Dupes" I want to sort by
ReceivedTime, then loop through if subject and received time are the
same. Anyway, sort doesn't work here. Only think I can think of is
maybe there is more than one items collection somehow (got that from
Sue Mosher's posts *thanks*). Any ideas? Thanks. -Noelani Rodriguez

-----------------------
Set objNameSpace = objOutlook.GetNamespace("MAPI")
Set objInbox = objNameSpace.GetDefaultFolder(olFolderInbox)
Set objFolder = objInbox.Folders("Dupes")

objFolder.Items.Sort "[ReceivedTime]", True

'Read through all items and filter as necessary
For i = 1 To objFolder.Items.Count
Set objMail = objFolder.Items(i)

'Check for duplicates
If objMail.Subject = LastItemName And objMail.ReceivedTime =
LastReceivedTime Then
objMail.Delete
End If

LastItemName = objMail.Subject
MsgBox (LastItemName)
LastReceivedTime = objMail.ReceivedTime
MsgBox (LastReceivedTime)
Next i
 
You need an object variable for the Items collection you want sorted:

Set colItems = oibjFolder.Items
colItems.Sort "[ReceivedTime]", True
intCount = colItems.Count
For i = intCount to 1 Step -1
Set objItem = colItems(i)
' do stuff with objItem
Next

Note the use of a countdown loop -- required if you're removing items from
the collection.
 
Back
Top