Discussion:
Sorting an ItemsCollection
(too old to reply)
McKilty
2009-10-02 14:49:32 UTC
Permalink
Hello all,

I'm having trouble sorting an items collection. I'm sure that this is
a coding issue, but I don't know how to properly resolve it so I'd
like your help.

What I believe to be the issue is my items collection variable,
mItemCollection, is not declared as items, but then when I declare it
as such, my other code before it fails.

I very much appreciate any help you can give me.

--------------------------------------------------------
Dim myOutlook As Outlook.Application
Dim myNameSpace As Namespace
Dim myMailItem
Dim mItemCollection

Dim SafeMail

Dim Session
Dim Search
Dim SearchRoot As Redemption.RDOFolder

Set myOutlook = CreateObject("Outlook.Application")
Set myNameSpace = myOutlook.GetNamespace("MAPI")

Set Session = CreateObject("Redemption.RDOSession")
Session.Logon

Set SearchRoot = Session.Stores.DefaultStore.SearchRootFolder
Set Search = SearchRoot.Folders.Item("Current Sent & Received")

Set mItemCollection = Search.Items ' RDOItems

Set mItemCollection = mItemCollection.Restrict("[SentOn] > '" _
& Format(dteStart, "yyyy-mm-dd hh:nn:ss") _
& "' AND [SentOn] < '" & Format(dteEnd, "yyyy-mm-dd hh:nn:ss") &
"'")

Set mItemCollection.Sort "[ReceivedTime]", False
---------------------------------------------------------------

The error I receive is: Invalid column property tag value:
[ReceivedTime]


If I declare mItemCollection as Items then it fails with a Type
Mismatch on:

Set mItemCollection = Search.Items ' RDOItems


If I declare Search as Items then it fails with a Type Mismatch:

Set Search = SearchRoot.Folders.Item("Current Sent & Received")
Sue Mosher [MVP]
2009-10-02 14:57:01 UTC
Permalink
Declare it as RDOItems, not Items (which is an Outlook object, not a
Redemption object). According to the example at
http://www.dimastr.com/redemption/rdo/RDOItems.htm, you don't need the
brackets around [ReceivedTime]. Also, you may need to change the format of
your date/time terms in the search query to eliminate the seconds element.

Is there a specific reason why you're using Redemption and not the Outlook
object model?
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
Post by McKilty
Hello all,
I'm having trouble sorting an items collection. I'm sure that this is
a coding issue, but I don't know how to properly resolve it so I'd
like your help.
What I believe to be the issue is my items collection variable,
mItemCollection, is not declared as items, but then when I declare it
as such, my other code before it fails.
I very much appreciate any help you can give me.
--------------------------------------------------------
Dim myOutlook As Outlook.Application
Dim myNameSpace As Namespace
Dim myMailItem
Dim mItemCollection
Dim SafeMail
Dim Session
Dim Search
Dim SearchRoot As Redemption.RDOFolder
Set myOutlook = CreateObject("Outlook.Application")
Set myNameSpace = myOutlook.GetNamespace("MAPI")
Set Session = CreateObject("Redemption.RDOSession")
Session.Logon
Set SearchRoot = Session.Stores.DefaultStore.SearchRootFolder
Set Search = SearchRoot.Folders.Item("Current Sent & Received")
Set mItemCollection = Search.Items ' RDOItems
Set mItemCollection = mItemCollection.Restrict("[SentOn] > '" _
& Format(dteStart, "yyyy-mm-dd hh:nn:ss") _
& "' AND [SentOn] < '" & Format(dteEnd, "yyyy-mm-dd hh:nn:ss") &
"'")
Set mItemCollection.Sort "[ReceivedTime]", False
---------------------------------------------------------------
[ReceivedTime]
If I declare mItemCollection as Items then it fails with a Type
Set mItemCollection = Search.Items ' RDOItems
Set Search = SearchRoot.Folders.Item("Current Sent & Received")
McKilty
2009-10-02 15:04:33 UTC
Permalink
I am using Outlook 2003 and the folder in question is in the Search
Folders. That's out of my experience, but Ken and Dmitry were helping
me.

I'll try RDOItems, thank you. Two additional questions:

1 - Can I sort by Conversation Topic?
2 - Can I sort by two fields?
Post by Sue Mosher [MVP]
Declare it as RDOItems, not Items (which is an Outlook object, not a
Redemption object). According to the example athttp://www.dimastr.com/redemption/rdo/RDOItems.htm, you don't need the
brackets around [ReceivedTime]. Also, you may need to change the format of
your date/time terms in the search query to eliminate the seconds element.
Is there a specific reason why you're using Redemption and not the Outlook
object model?
--
Sue Mosher, Outlook MVP
     Jumpstart for Power Users and Administrators
   http://www.outlookcode.com/article.aspx?id=54
McKilty
2009-10-02 15:39:38 UTC
Permalink
That works Sue, is it possible to do this in some way:

Set mItemCollection.Sort "[ConversationTopic]", False 'Ascending
Set mItemCollection.Sort "[ReceivedTime]", True
'Descending
Sue Mosher [MVP]
2009-10-02 15:56:05 UTC
Permalink
You can certainly run that code, but I don't know that it will give you the
results you're looking for. My advice is that you simply try it.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
Post by McKilty
Set mItemCollection.Sort "[ConversationTopic]", False 'Ascending
Set mItemCollection.Sort "[ReceivedTime]", True
'Descending
McKilty
2009-10-02 16:04:31 UTC
Permalink
Post by Sue Mosher [MVP]
You can certainly run that code, but I don't know that it will give you the
results you're looking for. My advice is that you simply try it.
--
Sue Mosher, Outlook MVP
     Jumpstart for Power Users and Administrators
   http://www.outlookcode.com/article.aspx?id=54
Yeah, I doubt it will. I think the second line will overwrite the
first. I was just hoping for something that would have both sorts in
the same line, like...

Set mItemCollection.Sort "[ConversationTopic] ASC AND [ReceivedTime]
DESC"
Sue Mosher [MVP]
2009-10-02 15:34:26 UTC
Permalink
1) I think so. Why not try it yourself and see?

2) You can apply Sort twice, but I'm not sure it will give you the results
you seek (whatever those might be -- not clear from your post).
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"McKilty" <***@gmail.com> wrote in message news:14d14f69-d3f8-467e-83d2-***@v25g2000yqk.googlegroups.com...
I am using Outlook 2003 and the folder in question is in the Search
Folders. That's out of my experience, but Ken and Dmitry were helping
me.

I'll try RDOItems, thank you. Two additional questions:

1 - Can I sort by Conversation Topic?
2 - Can I sort by two fields?
Post by Sue Mosher [MVP]
Declare it as RDOItems, not Items (which is an Outlook object, not a
Redemption object). According to the example
athttp://www.dimastr.com/redemption/rdo/RDOItems.htm, you don't need the
brackets around [ReceivedTime]. Also, you may need to change the format of
your date/time terms in the search query to eliminate the seconds element.
Is there a specific reason why you're using Redemption and not the Outlook
object model?
McKilty
2009-10-02 16:06:29 UTC
Permalink
Post by Sue Mosher [MVP]
1) I think so. Why not try it yourself and see?
2) You can apply Sort twice, but I'm not sure it will give you the results
you seek (whatever those might be -- not clear from your post).
--
Sue Mosher, Outlook MVP
     Jumpstart for Power Users and Administrators
   http://www.outlookcode.com/article.aspx?id=54
Yeah, I realized after that #1 was kind of a pointless question after
I posted it.
Rolf G. Bercht
2010-05-15 13:50:26 UTC
Permalink
@McKilty: you CAN sort for more than 1 fields using this:

sortfields = "[Subject] [Start] [End]"

sortedItems.sort sortfields

It works for any named attributes for all items within the sortedItems
collection which possess the given attributes and for which sorting is
allowed (e.g., not for [Categories])

Rolf

url:http://www.ureader.com/msg/11031607.aspx

Loading...