Message filtering in collection does not work

P

Peter Suba

Hello,



It seems like filtering for COnversationtopic does not really work.
Can You tell me what can cause this?

See the following snippet:

CntB=0

oMsgs.Filter = Nothing
Set objMsgFilter = oMsgs.Filter
objMsgFilter.Type = "IPM.Post.Ticketing list display form"
objMsgFilter.Fields("ConversationTopic") = ConvTopic
For Each oMsg In oMsgs
If oMsg.ConversationTopic <> ConvTopic Then
CntB = CntB + 1
End If
If oMsg.EntryID <> Item.EntryID _
And oMsg.ReceivedTime < Item.ReceivedTime _
And oMsg.ConversationTopic = ConvTopic Then
blnIsFirst = False
Exit For
End If
Next

If 0<>CntB Then
MsgBox "Filter does not work." & vbCrLf & _
"Found additional messages: " & CntB
End If



In this part, CntB should always be 0 because there is filtering for the
conversationtopic field. However, I regularly get well above 0 values in the
popup box when I run this code.

BTW I also tried objMsgFilter.ConversationTopic = ConvTopic instead of
objMsgFilter.Fields("ConversationTopic") = ConvTopic with no effect.

Peter
 
K

Ken Slovak - [MVP - Outlook]

Have you tried using the property tag for that (0x70001E) instead of the
Field name?
 
P

Peter Suba

Hi Ken,

I have tried this with the property tag but with the same result.
Is there a way to check if the filter accepted this property?

Peter
 
K

Ken Slovak - [MVP - Outlook]

You can check for errors both when you assign the filter and when you
attempt to retrieve items in the filtered Messages collection. If the filter
spec isn't workable you should get a CdoE_TOO_COMPLEX error.
 
P

Peter Suba

Hi Ken,

I did that now (vive la "On Error Resume Next") and indeed I do receive an
error even before getting to the definition of filter criteria.

Indeed, when defining the filter in the following line:

Set objMsgFilter = oMsgs.Filter

I get an error " The object does not support this method or property"...

This is in Sub Item_Open() and the oMsgs object is defined as

Set oMsgs = Item.Parent.Items

So this should be a perfectly valid property, no?

Peter
 
K

Ken Slovak - [MVP - Outlook]

You're confusing Outlook object model code and CDO code. Once you get a
MAPIFolder (Outlook) you can get the folder as a CDO Folder object. That has
a Messages collection, not an Items collection. It's the Messages collection
that would have a MessageFilter object, not the Outlook Items collection.
 
P

Peter Suba

Hi Ken,

You were perfectly right. (thats what happens if You turn to system
administration for 5 years and return to your old code after that time to
enhance it... :-( )
Managed to modify the code so that I get the correct Messages collection -
and so filtering now works as expected.

Thanks for the help!

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top