Home All Groups Group Topic Archive Search About

Using Restrict method to select emails

Author
25 Apr 2007 5:15 PM
Jerry West
I'm trying to use the .Restrict method to select emails within the Inbox:

    sSearch$ = "[From] = 'Jake Parlance'"

    Set fldFolder = CRM.O.AppNameSpace.GetDefaultFolder(olFolderInbox)

    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)

This works just fine if the email in question has in its From field the name
Jake Parlance. But if I only know Jake Parlance's email address then it
would fail:

sSearch$ = "[From] = 'jparla***@fake.email.com'"

I assume it fails because the email address is "resolved" to the person's
actual name. I'd like to be able to search using only the email address
without needing to know the person's name. Is there a way to do this? I
tried:

sSearch$ = "[E-mail] = 'jparla***@fake.email.com'"

This did not work because I assume "[E-mail]" is not a "keyword"? Is it
possible to search using email only?

Also, where does one find a list of all the "keywords", like "[From]"?

Thanks!

JW

Author
25 Apr 2007 5:28 PM
Dmitry Streblechenko
Use the SenderEmailAddress property in your restriction.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy  - Outlook, CDO
and MAPI Developer Tool

Show quote
"Jerry West" <j*@comcast.net> wrote in message
news:132v35thp7h1jd4@news.supernews.com...
> I'm trying to use the .Restrict method to select emails within the Inbox:
>
>    sSearch$ = "[From] = 'Jake Parlance'"
>
>    Set fldFolder = CRM.O.AppNameSpace.GetDefaultFolder(olFolderInbox)
>
>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>
> This works just fine if the email in question has in its From field the
> name Jake Parlance. But if I only know Jake Parlance's email address then
> it would fail:
>
> sSearch$ = "[From] = 'jparla***@fake.email.com'"
>
> I assume it fails because the email address is "resolved" to the person's
> actual name. I'd like to be able to search using only the email address
> without needing to know the person's name. Is there a way to do this? I
> tried:
>
> sSearch$ = "[E-mail] = 'jparla***@fake.email.com'"
>
> This did not work because I assume "[E-mail]" is not a "keyword"? Is it
> possible to search using email only?
>
> Also, where does one find a list of all the "keywords", like "[From]"?
>
> Thanks!
>
> JW
>
Author
25 Apr 2007 6:01 PM
Jerry West
Thank you for your answer. Where does one find a list of these "keywords"?
For, example SenderEmailAddress or From? Is there a list of these keywords
anywhere?

Is "To" a valid keyword? I am trying to select emails based on who the email
was sent to from within the Sent Items folder:

    sSearch$ = "[To] = 'jake.f***@bademail.com'"

    Set fldFolder = CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)

    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)

The objItemsCollection.Count property is always 0. So I'm wondering if "To"
is a keyword? If not, what should I be using and where does one find these
keywords?

Thanks,

JW

Show quote
"Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
news:%230RmY71hHHA.4064@TK2MSFTNGP02.phx.gbl...
> Use the SenderEmailAddress property in your restriction.
>
> Dmitry Streblechenko (MVP)
> http://www.dimastr.com/
> OutlookSpy  - Outlook, CDO
> and MAPI Developer Tool
>
> "Jerry West" <j*@comcast.net> wrote in message
> news:132v35thp7h1jd4@news.supernews.com...
>> I'm trying to use the .Restrict method to select emails within the Inbox:
>>
>>    sSearch$ = "[From] = 'Jake Parlance'"
>>
>>    Set fldFolder = CRM.O.AppNameSpace.GetDefaultFolder(olFolderInbox)
>>
>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>
>> This works just fine if the email in question has in its From field the
>> name Jake Parlance. But if I only know Jake Parlance's email address then
>> it would fail:
>>
>> sSearch$ = "[From] = 'jparla***@fake.email.com'"
>>
>> I assume it fails because the email address is "resolved" to the person's
>> actual name. I'd like to be able to search using only the email address
>> without needing to know the person's name. Is there a way to do this? I
>> tried:
>>
>> sSearch$ = "[E-mail] = 'jparla***@fake.email.com'"
>>
>> This did not work because I assume "[E-mail]" is not a "keyword"? Is it
>> possible to search using email only?
>>
>> Also, where does one find a list of all the "keywords", like "[From]"?
>>
>> Thanks!
>>
>> JW
>>
>
>
Author
25 Apr 2007 6:33 PM
Dmitry Streblechenko
It is just an Outlook property name, as in MailItem.SenderEmailAddress. Have
you actually tried it?
To property in most cases includes both names and addresses and corresponds
to the PR_DISPLAY_TO MAPI property (look at messages with MFCMAPI or
OutlookSpy), so your restriction won't match any messages.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy  - Outlook, CDO
and MAPI Developer Tool

Show quote
"Jerry West" <j*@comcast.net> wrote in message
news:132v5rb59ckh43a@news.supernews.com...
> Thank you for your answer. Where does one find a list of these "keywords"?
> For, example SenderEmailAddress or From? Is there a list of these keywords
> anywhere?
>
> Is "To" a valid keyword? I am trying to select emails based on who the
> email was sent to from within the Sent Items folder:
>
>    sSearch$ = "[To] = 'jake.f***@bademail.com'"
>
>    Set fldFolder = CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)
>
>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>
> The objItemsCollection.Count property is always 0. So I'm wondering if
> "To" is a keyword? If not, what should I be using and where does one find
> these keywords?
>
> Thanks,
>
> JW
>
> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
> news:%230RmY71hHHA.4064@TK2MSFTNGP02.phx.gbl...
>> Use the SenderEmailAddress property in your restriction.
>>
>> Dmitry Streblechenko (MVP)
>> http://www.dimastr.com/
>> OutlookSpy  - Outlook, CDO
>> and MAPI Developer Tool
>>
>> "Jerry West" <j*@comcast.net> wrote in message
>> news:132v35thp7h1jd4@news.supernews.com...
>>> I'm trying to use the .Restrict method to select emails within the
>>> Inbox:
>>>
>>>    sSearch$ = "[From] = 'Jake Parlance'"
>>>
>>>    Set fldFolder = CRM.O.AppNameSpace.GetDefaultFolder(olFolderInbox)
>>>
>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>
>>> This works just fine if the email in question has in its From field the
>>> name Jake Parlance. But if I only know Jake Parlance's email address
>>> then it would fail:
>>>
>>> sSearch$ = "[From] = 'jparla***@fake.email.com'"
>>>
>>> I assume it fails because the email address is "resolved" to the
>>> person's actual name. I'd like to be able to search using only the email
>>> address without needing to know the person's name. Is there a way to do
>>> this? I tried:
>>>
>>> sSearch$ = "[E-mail] = 'jparla***@fake.email.com'"
>>>
>>> This did not work because I assume "[E-mail]" is not a "keyword"? Is it
>>> possible to search using email only?
>>>
>>> Also, where does one find a list of all the "keywords", like "[From]"?
>>>
>>> Thanks!
>>>
>>> JW
>>>
>>
>>
>
>
Author
25 Apr 2007 6:42 PM
Jerry West
>> as in MailItem.SenderEmailAddress. Have you actually tried it?

Yes, it worked great.

>> To property in most cases includes both names and addresses

So then the code I show should work, right? I checked the email and I see
that the "To" field shows the email address versus the actual name:

    sSearch$ = "[To] = 'jake.f***@bademail.com'"

    Set fldFolder = CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)

    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)

Is the above not valid for selecting an email address of
jake.f***@bademail.com within the Sent Items folder? If not, what is the
proper way to do it? Can you show an example? I have tried the above on my
system and it does not locate the email address in the Sent Items folder
that I know is there.

Thanks,

JW


Show quote
"Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
news:eFQbPf2hHHA.1048@TK2MSFTNGP04.phx.gbl...
> It is just an Outlook property name, as in MailItem.SenderEmailAddress.
> Have you actually tried it?
> To property in most cases includes both names and addresses and
> corresponds to the PR_DISPLAY_TO MAPI property (look at messages with
> MFCMAPI or OutlookSpy), so your restriction won't match any messages.
>
> Dmitry Streblechenko (MVP)
> http://www.dimastr.com/
> OutlookSpy  - Outlook, CDO
> and MAPI Developer Tool
>
> "Jerry West" <j*@comcast.net> wrote in message
> news:132v5rb59ckh43a@news.supernews.com...
>> Thank you for your answer. Where does one find a list of these
>> "keywords"? For, example SenderEmailAddress or From? Is there a list of
>> these keywords anywhere?
>>
>> Is "To" a valid keyword? I am trying to select emails based on who the
>> email was sent to from within the Sent Items folder:
>>
>>    sSearch$ = "[To] = 'jake.f***@bademail.com'"
>>
>>    Set fldFolder = CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)
>>
>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>
>> The objItemsCollection.Count property is always 0. So I'm wondering if
>> "To" is a keyword? If not, what should I be using and where does one find
>> these keywords?
>>
>> Thanks,
>>
>> JW
>>
>> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
>> news:%230RmY71hHHA.4064@TK2MSFTNGP02.phx.gbl...
>>> Use the SenderEmailAddress property in your restriction.
>>>
>>> Dmitry Streblechenko (MVP)
>>> http://www.dimastr.com/
>>> OutlookSpy  - Outlook, CDO
>>> and MAPI Developer Tool
>>>
>>> "Jerry West" <j*@comcast.net> wrote in message
>>> news:132v35thp7h1jd4@news.supernews.com...
>>>> I'm trying to use the .Restrict method to select emails within the
>>>> Inbox:
>>>>
>>>>    sSearch$ = "[From] = 'Jake Parlance'"
>>>>
>>>>    Set fldFolder = CRM.O.AppNameSpace.GetDefaultFolder(olFolderInbox)
>>>>
>>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>>
>>>> This works just fine if the email in question has in its From field the
>>>> name Jake Parlance. But if I only know Jake Parlance's email address
>>>> then it would fail:
>>>>
>>>> sSearch$ = "[From] = 'jparla***@fake.email.com'"
>>>>
>>>> I assume it fails because the email address is "resolved" to the
>>>> person's actual name. I'd like to be able to search using only the
>>>> email address without needing to know the person's name. Is there a way
>>>> to do this? I tried:
>>>>
>>>> sSearch$ = "[E-mail] = 'jparla***@fake.email.com'"
>>>>
>>>> This did not work because I assume "[E-mail]" is not a "keyword"? Is it
>>>> possible to search using email only?
>>>>
>>>> Also, where does one find a list of all the "keywords", like "[From]"?
>>>>
>>>> Thanks!
>>>>
>>>> JW
>>>>
>>>
>>>
>>
>>
>
>
Author
25 Apr 2007 6:55 PM
Dmitry Streblechenko
No, [To] won't work since you are not including the name (it may or rmay not
be there)- look at messages with OutlookSpy. most likely To (and
PR_DISPLAY_TO MAPI) will be something like "Jerry West" or "Jerry West
<j*@comcast.net>"
Do use SenderEmailAddress.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy  - Outlook, CDO
and MAPI Developer Tool

Show quote
"Jerry West" <j*@comcast.net> wrote in message
news:132v88otfh1gff7@news.supernews.com...
>>> as in MailItem.SenderEmailAddress. Have you actually tried it?
>
> Yes, it worked great.
>
>>> To property in most cases includes both names and addresses
>
> So then the code I show should work, right? I checked the email and I see
> that the "To" field shows the email address versus the actual name:
>
>    sSearch$ = "[To] = 'jake.f***@bademail.com'"
>
>    Set fldFolder = CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)
>
>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>
> Is the above not valid for selecting an email address of
> jake.f***@bademail.com within the Sent Items folder? If not, what is the
> proper way to do it? Can you show an example? I have tried the above on my
> system and it does not locate the email address in the Sent Items folder
> that I know is there.
>
> Thanks,
>
> JW
>
>
> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
> news:eFQbPf2hHHA.1048@TK2MSFTNGP04.phx.gbl...
>> It is just an Outlook property name, as in MailItem.SenderEmailAddress.
>> Have you actually tried it?
>> To property in most cases includes both names and addresses and
>> corresponds to the PR_DISPLAY_TO MAPI property (look at messages with
>> MFCMAPI or OutlookSpy), so your restriction won't match any messages.
>>
>> Dmitry Streblechenko (MVP)
>> http://www.dimastr.com/
>> OutlookSpy  - Outlook, CDO
>> and MAPI Developer Tool
>>
>> "Jerry West" <j*@comcast.net> wrote in message
>> news:132v5rb59ckh43a@news.supernews.com...
>>> Thank you for your answer. Where does one find a list of these
>>> "keywords"? For, example SenderEmailAddress or From? Is there a list of
>>> these keywords anywhere?
>>>
>>> Is "To" a valid keyword? I am trying to select emails based on who the
>>> email was sent to from within the Sent Items folder:
>>>
>>>    sSearch$ = "[To] = 'jake.f***@bademail.com'"
>>>
>>>    Set fldFolder = CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)
>>>
>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>
>>> The objItemsCollection.Count property is always 0. So I'm wondering if
>>> "To" is a keyword? If not, what should I be using and where does one
>>> find these keywords?
>>>
>>> Thanks,
>>>
>>> JW
>>>
>>> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
>>> news:%230RmY71hHHA.4064@TK2MSFTNGP02.phx.gbl...
>>>> Use the SenderEmailAddress property in your restriction.
>>>>
>>>> Dmitry Streblechenko (MVP)
>>>> http://www.dimastr.com/
>>>> OutlookSpy  - Outlook, CDO
>>>> and MAPI Developer Tool
>>>>
>>>> "Jerry West" <j*@comcast.net> wrote in message
>>>> news:132v35thp7h1jd4@news.supernews.com...
>>>>> I'm trying to use the .Restrict method to select emails within the
>>>>> Inbox:
>>>>>
>>>>>    sSearch$ = "[From] = 'Jake Parlance'"
>>>>>
>>>>>    Set fldFolder = CRM.O.AppNameSpace.GetDefaultFolder(olFolderInbox)
>>>>>
>>>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>>>
>>>>> This works just fine if the email in question has in its From field
>>>>> the name Jake Parlance. But if I only know Jake Parlance's email
>>>>> address then it would fail:
>>>>>
>>>>> sSearch$ = "[From] = 'jparla***@fake.email.com'"
>>>>>
>>>>> I assume it fails because the email address is "resolved" to the
>>>>> person's actual name. I'd like to be able to search using only the
>>>>> email address without needing to know the person's name. Is there a
>>>>> way to do this? I tried:
>>>>>
>>>>> sSearch$ = "[E-mail] = 'jparla***@fake.email.com'"
>>>>>
>>>>> This did not work because I assume "[E-mail]" is not a "keyword"? Is
>>>>> it possible to search using email only?
>>>>>
>>>>> Also, where does one find a list of all the "keywords", like "[From]"?
>>>>>
>>>>> Thanks!
>>>>>
>>>>> JW
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
25 Apr 2007 7:41 PM
Jerry West
I can look at the message in the VB6 IDE. I see that the .To property reads
jake.f***@bademail.com. No name is included.

What I am trying to do is select a email based on the To property (or any
property that indicates who the email was sent to).

Since I have one email in the Sent Items folder and because I can see that
this item's To property value is set at jake.f***@bademail.com I setup my
search string like so:

    sSearch$ = "[To] = 'jake.f***@bademail.com'"

I then search the Sent Items folder for the email:

    Set fldFolder = CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)

    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)

Unfortunately, this fails. If the To property, as viewed in the debug window
of the VB6 IDE, is set at jake.f***@bademail.com then why would this code
fail?

The SenderEmailAddress property can not be used in this scenario since it
does not return who the email was sent to. The To property and
SenderEmailAddress do not correspond.

JW

Show quote
"Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
news:u%23%23Exr2hHHA.392@TK2MSFTNGP06.phx.gbl...
> No, [To] won't work since you are not including the name (it may or rmay
> not be there)- look at messages with OutlookSpy. most likely To (and
> PR_DISPLAY_TO MAPI) will be something like "Jerry West" or "Jerry West
> <j*@comcast.net>"
> Do use SenderEmailAddress.
>
> Dmitry Streblechenko (MVP)
> http://www.dimastr.com/
> OutlookSpy  - Outlook, CDO
> and MAPI Developer Tool
>
> "Jerry West" <j*@comcast.net> wrote in message
> news:132v88otfh1gff7@news.supernews.com...
>>>> as in MailItem.SenderEmailAddress. Have you actually tried it?
>>
>> Yes, it worked great.
>>
>>>> To property in most cases includes both names and addresses
>>
>> So then the code I show should work, right? I checked the email and I see
>> that the "To" field shows the email address versus the actual name:
>>
>>    sSearch$ = "[To] = 'jake.f***@bademail.com'"
>>
>>    Set fldFolder = CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)
>>
>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>
>> Is the above not valid for selecting an email address of
>> jake.f***@bademail.com within the Sent Items folder? If not, what is the
>> proper way to do it? Can you show an example? I have tried the above on
>> my system and it does not locate the email address in the Sent Items
>> folder that I know is there.
>>
>> Thanks,
>>
>> JW
>>
>>
>> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
>> news:eFQbPf2hHHA.1048@TK2MSFTNGP04.phx.gbl...
>>> It is just an Outlook property name, as in MailItem.SenderEmailAddress.
>>> Have you actually tried it?
>>> To property in most cases includes both names and addresses and
>>> corresponds to the PR_DISPLAY_TO MAPI property (look at messages with
>>> MFCMAPI or OutlookSpy), so your restriction won't match any messages.
>>>
>>> Dmitry Streblechenko (MVP)
>>> http://www.dimastr.com/
>>> OutlookSpy  - Outlook, CDO
>>> and MAPI Developer Tool
>>>
>>> "Jerry West" <j*@comcast.net> wrote in message
>>> news:132v5rb59ckh43a@news.supernews.com...
>>>> Thank you for your answer. Where does one find a list of these
>>>> "keywords"? For, example SenderEmailAddress or From? Is there a list of
>>>> these keywords anywhere?
>>>>
>>>> Is "To" a valid keyword? I am trying to select emails based on who the
>>>> email was sent to from within the Sent Items folder:
>>>>
>>>>    sSearch$ = "[To] = 'jake.f***@bademail.com'"
>>>>
>>>>    Set fldFolder =
>>>> CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)
>>>>
>>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>>
>>>> The objItemsCollection.Count property is always 0. So I'm wondering if
>>>> "To" is a keyword? If not, what should I be using and where does one
>>>> find these keywords?
>>>>
>>>> Thanks,
>>>>
>>>> JW
>>>>
>>>> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
>>>> news:%230RmY71hHHA.4064@TK2MSFTNGP02.phx.gbl...
>>>>> Use the SenderEmailAddress property in your restriction.
>>>>>
>>>>> Dmitry Streblechenko (MVP)
>>>>> http://www.dimastr.com/
>>>>> OutlookSpy  - Outlook, CDO
>>>>> and MAPI Developer Tool
>>>>>
>>>>> "Jerry West" <j*@comcast.net> wrote in message
>>>>> news:132v35thp7h1jd4@news.supernews.com...
>>>>>> I'm trying to use the .Restrict method to select emails within the
>>>>>> Inbox:
>>>>>>
>>>>>>    sSearch$ = "[From] = 'Jake Parlance'"
>>>>>>
>>>>>>    Set fldFolder = CRM.O.AppNameSpace.GetDefaultFolder(olFolderInbox)
>>>>>>
>>>>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>>>>
>>>>>> This works just fine if the email in question has in its From field
>>>>>> the name Jake Parlance. But if I only know Jake Parlance's email
>>>>>> address then it would fail:
>>>>>>
>>>>>> sSearch$ = "[From] = 'jparla***@fake.email.com'"
>>>>>>
>>>>>> I assume it fails because the email address is "resolved" to the
>>>>>> person's actual name. I'd like to be able to search using only the
>>>>>> email address without needing to know the person's name. Is there a
>>>>>> way to do this? I tried:
>>>>>>
>>>>>> sSearch$ = "[E-mail] = 'jparla***@fake.email.com'"
>>>>>>
>>>>>> This did not work because I assume "[E-mail]" is not a "keyword"? Is
>>>>>> it possible to search using email only?
>>>>>>
>>>>>> Also, where does one find a list of all the "keywords", like
>>>>>> "[From]"?
>>>>>>
>>>>>> Thanks!
>>>>>>
>>>>>> JW
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
25 Apr 2007 8:28 PM
Dmitry Streblechenko
I have no problem running the following script

set Folder = Application.ActiveExplorer.CurrentFolder
set RestrItems = Folder.Items.Restrict("[To] = 'Dmitry Streblechenko'")
MsgBox RestrItems.Count

Can you run it from OutlookSpy? Select a folder where you want to search,
click the "Script Editor" button on the OutlookSpy toolbar, paste the
script, modify the condition appropriately, click Run.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy  - Outlook, CDO
and MAPI Developer Tool

Show quote
"Jerry West" <j*@comcast.net> wrote in message
news:132vbn7ph6evn4d@news.supernews.com...
>I can look at the message in the VB6 IDE. I see that the .To property reads
>jake.f***@bademail.com. No name is included.
>
> What I am trying to do is select a email based on the To property (or any
> property that indicates who the email was sent to).
>
> Since I have one email in the Sent Items folder and because I can see that
> this item's To property value is set at jake.f***@bademail.com I setup my
> search string like so:
>
>    sSearch$ = "[To] = 'jake.f***@bademail.com'"
>
> I then search the Sent Items folder for the email:
>
>    Set fldFolder = CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)
>
>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>
> Unfortunately, this fails. If the To property, as viewed in the debug
> window of the VB6 IDE, is set at jake.f***@bademail.com then why would
> this code fail?
>
> The SenderEmailAddress property can not be used in this scenario since it
> does not return who the email was sent to. The To property and
> SenderEmailAddress do not correspond.
>
> JW
>
> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
> news:u%23%23Exr2hHHA.392@TK2MSFTNGP06.phx.gbl...
>> No, [To] won't work since you are not including the name (it may or rmay
>> not be there)- look at messages with OutlookSpy. most likely To (and
>> PR_DISPLAY_TO MAPI) will be something like "Jerry West" or "Jerry West
>> <j*@comcast.net>"
>> Do use SenderEmailAddress.
>>
>> Dmitry Streblechenko (MVP)
>> http://www.dimastr.com/
>> OutlookSpy  - Outlook, CDO
>> and MAPI Developer Tool
>>
>> "Jerry West" <j*@comcast.net> wrote in message
>> news:132v88otfh1gff7@news.supernews.com...
>>>>> as in MailItem.SenderEmailAddress. Have you actually tried it?
>>>
>>> Yes, it worked great.
>>>
>>>>> To property in most cases includes both names and addresses
>>>
>>> So then the code I show should work, right? I checked the email and I
>>> see that the "To" field shows the email address versus the actual name:
>>>
>>>    sSearch$ = "[To] = 'jake.f***@bademail.com'"
>>>
>>>    Set fldFolder = CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)
>>>
>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>
>>> Is the above not valid for selecting an email address of
>>> jake.f***@bademail.com within the Sent Items folder? If not, what is the
>>> proper way to do it? Can you show an example? I have tried the above on
>>> my system and it does not locate the email address in the Sent Items
>>> folder that I know is there.
>>>
>>> Thanks,
>>>
>>> JW
>>>
>>>
>>> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
>>> news:eFQbPf2hHHA.1048@TK2MSFTNGP04.phx.gbl...
>>>> It is just an Outlook property name, as in MailItem.SenderEmailAddress.
>>>> Have you actually tried it?
>>>> To property in most cases includes both names and addresses and
>>>> corresponds to the PR_DISPLAY_TO MAPI property (look at messages with
>>>> MFCMAPI or OutlookSpy), so your restriction won't match any messages.
>>>>
>>>> Dmitry Streblechenko (MVP)
>>>> http://www.dimastr.com/
>>>> OutlookSpy  - Outlook, CDO
>>>> and MAPI Developer Tool
>>>>
>>>> "Jerry West" <j*@comcast.net> wrote in message
>>>> news:132v5rb59ckh43a@news.supernews.com...
>>>>> Thank you for your answer. Where does one find a list of these
>>>>> "keywords"? For, example SenderEmailAddress or From? Is there a list
>>>>> of these keywords anywhere?
>>>>>
>>>>> Is "To" a valid keyword? I am trying to select emails based on who the
>>>>> email was sent to from within the Sent Items folder:
>>>>>
>>>>>    sSearch$ = "[To] = 'jake.f***@bademail.com'"
>>>>>
>>>>>    Set fldFolder =
>>>>> CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)
>>>>>
>>>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>>>
>>>>> The objItemsCollection.Count property is always 0. So I'm wondering if
>>>>> "To" is a keyword? If not, what should I be using and where does one
>>>>> find these keywords?
>>>>>
>>>>> Thanks,
>>>>>
>>>>> JW
>>>>>
>>>>> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
>>>>> news:%230RmY71hHHA.4064@TK2MSFTNGP02.phx.gbl...
>>>>>> Use the SenderEmailAddress property in your restriction.
>>>>>>
>>>>>> Dmitry Streblechenko (MVP)
>>>>>> http://www.dimastr.com/
>>>>>> OutlookSpy  - Outlook, CDO
>>>>>> and MAPI Developer Tool
>>>>>>
>>>>>> "Jerry West" <j*@comcast.net> wrote in message
>>>>>> news:132v35thp7h1jd4@news.supernews.com...
>>>>>>> I'm trying to use the .Restrict method to select emails within the
>>>>>>> Inbox:
>>>>>>>
>>>>>>>    sSearch$ = "[From] = 'Jake Parlance'"
>>>>>>>
>>>>>>>    Set fldFolder =
>>>>>>> CRM.O.AppNameSpace.GetDefaultFolder(olFolderInbox)
>>>>>>>
>>>>>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>>>>>
>>>>>>> This works just fine if the email in question has in its From field
>>>>>>> the name Jake Parlance. But if I only know Jake Parlance's email
>>>>>>> address then it would fail:
>>>>>>>
>>>>>>> sSearch$ = "[From] = 'jparla***@fake.email.com'"
>>>>>>>
>>>>>>> I assume it fails because the email address is "resolved" to the
>>>>>>> person's actual name. I'd like to be able to search using only the
>>>>>>> email address without needing to know the person's name. Is there a
>>>>>>> way to do this? I tried:
>>>>>>>
>>>>>>> sSearch$ = "[E-mail] = 'jparla***@fake.email.com'"
>>>>>>>
>>>>>>> This did not work because I assume "[E-mail]" is not a "keyword"? Is
>>>>>>> it possible to search using email only?
>>>>>>>
>>>>>>> Also, where does one find a list of all the "keywords", like
>>>>>>> "[From]"?
>>>>>>>
>>>>>>> Thanks!
>>>>>>>
>>>>>>> JW
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
25 Apr 2007 9:10 PM
Jerry West
> Can you run it from OutlookSpy? Select a folder where you want to search,
> click the "Script Editor" button on the OutlookSpy toolbar, paste the
> script, modify the condition appropriately, click Run.

set Folder = Application.ActiveExplorer.CurrentFolder
set RestrItems = Folder.Items.Restrict("[To] = 'jake.f***@bademail.com'")
MsgBox RestrItems.Count

Not sure how this was going to be different than what I was doing in VB but
I did try it. As in VB, .Count is zero. It fails to return the email which
has in its To property the email address of jake.f***@bademail.com.

If the To property of the email shows as jake.f***@bademail.com and the VB6
IDE also shows that is what the To property holds then shouldn't my code
work?

set Folder = Application.ActiveExplorer.CurrentFolder
set RestrItems = Folder.Items.Restrict("[To] = 'jake.f***@bademail.com'")
MsgBox RestrItems.Count

I have placed 5 emails in my Sent Items folder. I tried searching for each
one of them. I modified my restrict statement to reflect the value of the To
field whether it was an actual email address or the "resolved" name. In no
case did the search return a hit. There must be some explanation for this. I
am using the above code. I can see within the debug window of the VB IDE
that the Sent Items folder has the emails I am searching for in it --yet if
fails to return them. What could I be doing wrong? Is there another property
I could search upon that would yield the same data as the To property?

JW

JW

Show quote
"Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
news:OrJ7vf3hHHA.3512@TK2MSFTNGP06.phx.gbl...
>I have no problem running the following script
>
> set Folder = Application.ActiveExplorer.CurrentFolder
> set RestrItems = Folder.Items.Restrict("[To] = 'Dmitry Streblechenko'")
> MsgBox RestrItems.Count
>
> Can you run it from OutlookSpy? Select a folder where you want to search,
> click the "Script Editor" button on the OutlookSpy toolbar, paste the
> script, modify the condition appropriately, click Run.
>
> Dmitry Streblechenko (MVP)
> http://www.dimastr.com/
> OutlookSpy  - Outlook, CDO
> and MAPI Developer Tool
>
> "Jerry West" <j*@comcast.net> wrote in message
> news:132vbn7ph6evn4d@news.supernews.com...
>>I can look at the message in the VB6 IDE. I see that the .To property
>>reads jake.f***@bademail.com. No name is included.
>>
>> What I am trying to do is select a email based on the To property (or any
>> property that indicates who the email was sent to).
>>
>> Since I have one email in the Sent Items folder and because I can see
>> that this item's To property value is set at jake.f***@bademail.com I
>> setup my search string like so:
>>
>>    sSearch$ = "[To] = 'jake.f***@bademail.com'"
>>
>> I then search the Sent Items folder for the email:
>>
>>    Set fldFolder = CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)
>>
>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>
>> Unfortunately, this fails. If the To property, as viewed in the debug
>> window of the VB6 IDE, is set at jake.f***@bademail.com then why would
>> this code fail?
>>
>> The SenderEmailAddress property can not be used in this scenario since it
>> does not return who the email was sent to. The To property and
>> SenderEmailAddress do not correspond.
>>
>> JW
>>
>> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
>> news:u%23%23Exr2hHHA.392@TK2MSFTNGP06.phx.gbl...
>>> No, [To] won't work since you are not including the name (it may or rmay
>>> not be there)- look at messages with OutlookSpy. most likely To (and
>>> PR_DISPLAY_TO MAPI) will be something like "Jerry West" or "Jerry West
>>> <j*@comcast.net>"
>>> Do use SenderEmailAddress.
>>>
>>> Dmitry Streblechenko (MVP)
>>> http://www.dimastr.com/
>>> OutlookSpy  - Outlook, CDO
>>> and MAPI Developer Tool
>>>
>>> "Jerry West" <j*@comcast.net> wrote in message
>>> news:132v88otfh1gff7@news.supernews.com...
>>>>>> as in MailItem.SenderEmailAddress. Have you actually tried it?
>>>>
>>>> Yes, it worked great.
>>>>
>>>>>> To property in most cases includes both names and addresses
>>>>
>>>> So then the code I show should work, right? I checked the email and I
>>>> see that the "To" field shows the email address versus the actual name:
>>>>
>>>>    sSearch$ = "[To] = 'jake.f***@bademail.com'"
>>>>
>>>>    Set fldFolder =
>>>> CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)
>>>>
>>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>>
>>>> Is the above not valid for selecting an email address of
>>>> jake.f***@bademail.com within the Sent Items folder? If not, what is
>>>> the proper way to do it? Can you show an example? I have tried the
>>>> above on my system and it does not locate the email address in the Sent
>>>> Items folder that I know is there.
>>>>
>>>> Thanks,
>>>>
>>>> JW
>>>>
>>>>
>>>> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
>>>> news:eFQbPf2hHHA.1048@TK2MSFTNGP04.phx.gbl...
>>>>> It is just an Outlook property name, as in
>>>>> MailItem.SenderEmailAddress. Have you actually tried it?
>>>>> To property in most cases includes both names and addresses and
>>>>> corresponds to the PR_DISPLAY_TO MAPI property (look at messages with
>>>>> MFCMAPI or OutlookSpy), so your restriction won't match any messages.
>>>>>
>>>>> Dmitry Streblechenko (MVP)
>>>>> http://www.dimastr.com/
>>>>> OutlookSpy  - Outlook, CDO
>>>>> and MAPI Developer Tool
>>>>>
>>>>> "Jerry West" <j*@comcast.net> wrote in message
>>>>> news:132v5rb59ckh43a@news.supernews.com...
>>>>>> Thank you for your answer. Where does one find a list of these
>>>>>> "keywords"? For, example SenderEmailAddress or From? Is there a list
>>>>>> of these keywords anywhere?
>>>>>>
>>>>>> Is "To" a valid keyword? I am trying to select emails based on who
>>>>>> the email was sent to from within the Sent Items folder:
>>>>>>
>>>>>>    sSearch$ = "[To] = 'jake.f***@bademail.com'"
>>>>>>
>>>>>>    Set fldFolder =
>>>>>> CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)
>>>>>>
>>>>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>>>>
>>>>>> The objItemsCollection.Count property is always 0. So I'm wondering
>>>>>> if "To" is a keyword? If not, what should I be using and where does
>>>>>> one find these keywords?
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>> JW
>>>>>>
>>>>>> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
>>>>>> news:%230RmY71hHHA.4064@TK2MSFTNGP02.phx.gbl...
>>>>>>> Use the SenderEmailAddress property in your restriction.
>>>>>>>
>>>>>>> Dmitry Streblechenko (MVP)
>>>>>>> http://www.dimastr.com/
>>>>>>> OutlookSpy  - Outlook, CDO
>>>>>>> and MAPI Developer Tool
>>>>>>>
>>>>>>> "Jerry West" <j*@comcast.net> wrote in message
>>>>>>> news:132v35thp7h1jd4@news.supernews.com...
>>>>>>>> I'm trying to use the .Restrict method to select emails within the
>>>>>>>> Inbox:
>>>>>>>>
>>>>>>>>    sSearch$ = "[From] = 'Jake Parlance'"
>>>>>>>>
>>>>>>>>    Set fldFolder =
>>>>>>>> CRM.O.AppNameSpace.GetDefaultFolder(olFolderInbox)
>>>>>>>>
>>>>>>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>>>>>>
>>>>>>>> This works just fine if the email in question has in its From field
>>>>>>>> the name Jake Parlance. But if I only know Jake Parlance's email
>>>>>>>> address then it would fail:
>>>>>>>>
>>>>>>>> sSearch$ = "[From] = 'jparla***@fake.email.com'"
>>>>>>>>
>>>>>>>> I assume it fails because the email address is "resolved" to the
>>>>>>>> person's actual name. I'd like to be able to search using only the
>>>>>>>> email address without needing to know the person's name. Is there a
>>>>>>>> way to do this? I tried:
>>>>>>>>
>>>>>>>> sSearch$ = "[E-mail] = 'jparla***@fake.email.com'"
>>>>>>>>
>>>>>>>> This did not work because I assume "[E-mail]" is not a "keyword"?
>>>>>>>> Is it possible to search using email only?
>>>>>>>>
>>>>>>>> Also, where does one find a list of all the "keywords", like
>>>>>>>> "[From]"?
>>>>>>>>
>>>>>>>> Thanks!
>>>>>>>>
>>>>>>>> JW
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
25 Apr 2007 9:20 PM
Jerry West
Further testing shows that the problem on exists with the Sent Items folder.
I can search using the To and From fields without issue on folders other
than the Sent Items folder. The search always fails when searching this
folder in particular. Is there some reason why this is? Is there some
condition to searching the Sent Items folder I'm not aware of?

Any help appreciated.

JW

Show quote
"Jerry West" <j*@comcast.net> wrote in message
news:132vgud8181ri3a@news.supernews.com...
>> Can you run it from OutlookSpy? Select a folder where you want to search,
>> click the "Script Editor" button on the OutlookSpy toolbar, paste the
>> script, modify the condition appropriately, click Run.
>
> set Folder = Application.ActiveExplorer.CurrentFolder
> set RestrItems = Folder.Items.Restrict("[To] = 'jake.f***@bademail.com'")
> MsgBox RestrItems.Count
>
> Not sure how this was going to be different than what I was doing in VB
> but I did try it. As in VB, .Count is zero. It fails to return the email
> which has in its To property the email address of jake.f***@bademail.com.
>
> If the To property of the email shows as jake.f***@bademail.com and the
> VB6 IDE also shows that is what the To property holds then shouldn't my
> code work?
>
> set Folder = Application.ActiveExplorer.CurrentFolder
> set RestrItems = Folder.Items.Restrict("[To] = 'jake.f***@bademail.com'")
> MsgBox RestrItems.Count
>
> I have placed 5 emails in my Sent Items folder. I tried searching for each
> one of them. I modified my restrict statement to reflect the value of the
> To field whether it was an actual email address or the "resolved" name. In
> no case did the search return a hit. There must be some explanation for
> this. I am using the above code. I can see within the debug window of the
> VB IDE that the Sent Items folder has the emails I am searching for in
> it --yet if fails to return them. What could I be doing wrong? Is there
> another property I could search upon that would yield the same data as the
> To property?
>
> JW
>
> JW
>
> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
> news:OrJ7vf3hHHA.3512@TK2MSFTNGP06.phx.gbl...
>>I have no problem running the following script
>>
>> set Folder = Application.ActiveExplorer.CurrentFolder
>> set RestrItems = Folder.Items.Restrict("[To] = 'Dmitry Streblechenko'")
>> MsgBox RestrItems.Count
>>
>> Can you run it from OutlookSpy? Select a folder where you want to search,
>> click the "Script Editor" button on the OutlookSpy toolbar, paste the
>> script, modify the condition appropriately, click Run.
>>
>> Dmitry Streblechenko (MVP)
>> http://www.dimastr.com/
>> OutlookSpy  - Outlook, CDO
>> and MAPI Developer Tool
>>
>> "Jerry West" <j*@comcast.net> wrote in message
>> news:132vbn7ph6evn4d@news.supernews.com...
>>>I can look at the message in the VB6 IDE. I see that the .To property
>>>reads jake.f***@bademail.com. No name is included.
>>>
>>> What I am trying to do is select a email based on the To property (or
>>> any property that indicates who the email was sent to).
>>>
>>> Since I have one email in the Sent Items folder and because I can see
>>> that this item's To property value is set at jake.f***@bademail.com I
>>> setup my search string like so:
>>>
>>>    sSearch$ = "[To] = 'jake.f***@bademail.com'"
>>>
>>> I then search the Sent Items folder for the email:
>>>
>>>    Set fldFolder = CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)
>>>
>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>
>>> Unfortunately, this fails. If the To property, as viewed in the debug
>>> window of the VB6 IDE, is set at jake.f***@bademail.com then why would
>>> this code fail?
>>>
>>> The SenderEmailAddress property can not be used in this scenario since
>>> it does not return who the email was sent to. The To property and
>>> SenderEmailAddress do not correspond.
>>>
>>> JW
>>>
>>> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
>>> news:u%23%23Exr2hHHA.392@TK2MSFTNGP06.phx.gbl...
>>>> No, [To] won't work since you are not including the name (it may or
>>>> rmay not be there)- look at messages with OutlookSpy. most likely To
>>>> (and PR_DISPLAY_TO MAPI) will be something like "Jerry West" or "Jerry
>>>> West <j*@comcast.net>"
>>>> Do use SenderEmailAddress.
>>>>
>>>> Dmitry Streblechenko (MVP)
>>>> http://www.dimastr.com/
>>>> OutlookSpy  - Outlook, CDO
>>>> and MAPI Developer Tool
>>>>
>>>> "Jerry West" <j*@comcast.net> wrote in message
>>>> news:132v88otfh1gff7@news.supernews.com...
>>>>>>> as in MailItem.SenderEmailAddress. Have you actually tried it?
>>>>>
>>>>> Yes, it worked great.
>>>>>
>>>>>>> To property in most cases includes both names and addresses
>>>>>
>>>>> So then the code I show should work, right? I checked the email and I
>>>>> see that the "To" field shows the email address versus the actual
>>>>> name:
>>>>>
>>>>>    sSearch$ = "[To] = 'jake.f***@bademail.com'"
>>>>>
>>>>>    Set fldFolder =
>>>>> CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)
>>>>>
>>>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>>>
>>>>> Is the above not valid for selecting an email address of
>>>>> jake.f***@bademail.com within the Sent Items folder? If not, what is
>>>>> the proper way to do it? Can you show an example? I have tried the
>>>>> above on my system and it does not locate the email address in the
>>>>> Sent Items folder that I know is there.
>>>>>
>>>>> Thanks,
>>>>>
>>>>> JW
>>>>>
>>>>>
>>>>> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
>>>>> news:eFQbPf2hHHA.1048@TK2MSFTNGP04.phx.gbl...
>>>>>> It is just an Outlook property name, as in
>>>>>> MailItem.SenderEmailAddress. Have you actually tried it?
>>>>>> To property in most cases includes both names and addresses and
>>>>>> corresponds to the PR_DISPLAY_TO MAPI property (look at messages with
>>>>>> MFCMAPI or OutlookSpy), so your restriction won't match any messages.
>>>>>>
>>>>>> Dmitry Streblechenko (MVP)
>>>>>> http://www.dimastr.com/
>>>>>> OutlookSpy  - Outlook, CDO
>>>>>> and MAPI Developer Tool
>>>>>>
>>>>>> "Jerry West" <j*@comcast.net> wrote in message
>>>>>> news:132v5rb59ckh43a@news.supernews.com...
>>>>>>> Thank you for your answer. Where does one find a list of these
>>>>>>> "keywords"? For, example SenderEmailAddress or From? Is there a list
>>>>>>> of these keywords anywhere?
>>>>>>>
>>>>>>> Is "To" a valid keyword? I am trying to select emails based on who
>>>>>>> the email was sent to from within the Sent Items folder:
>>>>>>>
>>>>>>>    sSearch$ = "[To] = 'jake.f***@bademail.com'"
>>>>>>>
>>>>>>>    Set fldFolder =
>>>>>>> CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)
>>>>>>>
>>>>>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>>>>>
>>>>>>> The objItemsCollection.Count property is always 0. So I'm wondering
>>>>>>> if "To" is a keyword? If not, what should I be using and where does
>>>>>>> one find these keywords?
>>>>>>>
>>>>>>> Thanks,
>>>>>>>
>>>>>>> JW
>>>>>>>
>>>>>>> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
>>>>>>> news:%230RmY71hHHA.4064@TK2MSFTNGP02.phx.gbl...
>>>>>>>> Use the SenderEmailAddress property in your restriction.
>>>>>>>>
>>>>>>>> Dmitry Streblechenko (MVP)
>>>>>>>> http://www.dimastr.com/
>>>>>>>> OutlookSpy  - Outlook, CDO
>>>>>>>> and MAPI Developer Tool
>>>>>>>>
>>>>>>>> "Jerry West" <j*@comcast.net> wrote in message
>>>>>>>> news:132v35thp7h1jd4@news.supernews.com...
>>>>>>>>> I'm trying to use the .Restrict method to select emails within the
>>>>>>>>> Inbox:
>>>>>>>>>
>>>>>>>>>    sSearch$ = "[From] = 'Jake Parlance'"
>>>>>>>>>
>>>>>>>>>    Set fldFolder =
>>>>>>>>> CRM.O.AppNameSpace.GetDefaultFolder(olFolderInbox)
>>>>>>>>>
>>>>>>>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>>>>>>>
>>>>>>>>> This works just fine if the email in question has in its From
>>>>>>>>> field the name Jake Parlance. But if I only know Jake Parlance's
>>>>>>>>> email address then it would fail:
>>>>>>>>>
>>>>>>>>> sSearch$ = "[From] = 'jparla***@fake.email.com'"
>>>>>>>>>
>>>>>>>>> I assume it fails because the email address is "resolved" to the
>>>>>>>>> person's actual name. I'd like to be able to search using only the
>>>>>>>>> email address without needing to know the person's name. Is there
>>>>>>>>> a way to do this? I tried:
>>>>>>>>>
>>>>>>>>> sSearch$ = "[E-mail] = 'jparla***@fake.email.com'"
>>>>>>>>>
>>>>>>>>> This did not work because I assume "[E-mail]" is not a "keyword"?
>>>>>>>>> Is it possible to search using email only?
>>>>>>>>>
>>>>>>>>> Also, where does one find a list of all the "keywords", like
>>>>>>>>> "[From]"?
>>>>>>>>>
>>>>>>>>> Thanks!
>>>>>>>>>
>>>>>>>>> JW
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
25 Apr 2007 10:54 PM
Dmitry Streblechenko
"which has in its To property the email address of jake.f***@bademail.com" -
this is not what your code does, your code restricts on the *exact* match
(which is different from "contains").
Are you sure there are no other characters in the To property? Such as
single quotes? Look at a matching message with OutlookSpy (click IMessage
button). What do you see in PR_DISPLAY_TO?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy  - Outlook, CDO
and MAPI Developer Tool

Show quote
"Jerry West" <j*@comcast.net> wrote in message
news:132vgud8181ri3a@news.supernews.com...
>> Can you run it from OutlookSpy? Select a folder where you want to search,
>> click the "Script Editor" button on the OutlookSpy toolbar, paste the
>> script, modify the condition appropriately, click Run.
>
> set Folder = Application.ActiveExplorer.CurrentFolder
> set RestrItems = Folder.Items.Restrict("[To] = 'jake.f***@bademail.com'")
> MsgBox RestrItems.Count
>
> Not sure how this was going to be different than what I was doing in VB
> but I did try it. As in VB, .Count is zero. It fails to return the email
> which has in its To property the email address of jake.f***@bademail.com.
>
> If the To property of the email shows as jake.f***@bademail.com and the
> VB6 IDE also shows that is what the To property holds then shouldn't my
> code work?
>
> set Folder = Application.ActiveExplorer.CurrentFolder
> set RestrItems = Folder.Items.Restrict("[To] = 'jake.f***@bademail.com'")
> MsgBox RestrItems.Count
>
> I have placed 5 emails in my Sent Items folder. I tried searching for each
> one of them. I modified my restrict statement to reflect the value of the
> To field whether it was an actual email address or the "resolved" name. In
> no case did the search return a hit. There must be some explanation for
> this. I am using the above code. I can see within the debug window of the
> VB IDE that the Sent Items folder has the emails I am searching for in
> it --yet if fails to return them. What could I be doing wrong? Is there
> another property I could search upon that would yield the same data as the
> To property?
>
> JW
>
> JW
>
> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
> news:OrJ7vf3hHHA.3512@TK2MSFTNGP06.phx.gbl...
>>I have no problem running the following script
>>
>> set Folder = Application.ActiveExplorer.CurrentFolder
>> set RestrItems = Folder.Items.Restrict("[To] = 'Dmitry Streblechenko'")
>> MsgBox RestrItems.Count
>>
>> Can you run it from OutlookSpy? Select a folder where you want to search,
>> click the "Script Editor" button on the OutlookSpy toolbar, paste the
>> script, modify the condition appropriately, click Run.
>>
>> Dmitry Streblechenko (MVP)
>> http://www.dimastr.com/
>> OutlookSpy  - Outlook, CDO
>> and MAPI Developer Tool
>>
>> "Jerry West" <j*@comcast.net> wrote in message
>> news:132vbn7ph6evn4d@news.supernews.com...
>>>I can look at the message in the VB6 IDE. I see that the .To property
>>>reads jake.f***@bademail.com. No name is included.
>>>
>>> What I am trying to do is select a email based on the To property (or
>>> any property that indicates who the email was sent to).
>>>
>>> Since I have one email in the Sent Items folder and because I can see
>>> that this item's To property value is set at jake.f***@bademail.com I
>>> setup my search string like so:
>>>
>>>    sSearch$ = "[To] = 'jake.f***@bademail.com'"
>>>
>>> I then search the Sent Items folder for the email:
>>>
>>>    Set fldFolder = CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)
>>>
>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>
>>> Unfortunately, this fails. If the To property, as viewed in the debug
>>> window of the VB6 IDE, is set at jake.f***@bademail.com then why would
>>> this code fail?
>>>
>>> The SenderEmailAddress property can not be used in this scenario since
>>> it does not return who the email was sent to. The To property and
>>> SenderEmailAddress do not correspond.
>>>
>>> JW
>>>
>>> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
>>> news:u%23%23Exr2hHHA.392@TK2MSFTNGP06.phx.gbl...
>>>> No, [To] won't work since you are not including the name (it may or
>>>> rmay not be there)- look at messages with OutlookSpy. most likely To
>>>> (and PR_DISPLAY_TO MAPI) will be something like "Jerry West" or "Jerry
>>>> West <j*@comcast.net>"
>>>> Do use SenderEmailAddress.
>>>>
>>>> Dmitry Streblechenko (MVP)
>>>> http://www.dimastr.com/
>>>> OutlookSpy  - Outlook, CDO
>>>> and MAPI Developer Tool
>>>>
>>>> "Jerry West" <j*@comcast.net> wrote in message
>>>> news:132v88otfh1gff7@news.supernews.com...
>>>>>>> as in MailItem.SenderEmailAddress. Have you actually tried it?
>>>>>
>>>>> Yes, it worked great.
>>>>>
>>>>>>> To property in most cases includes both names and addresses
>>>>>
>>>>> So then the code I show should work, right? I checked the email and I
>>>>> see that the "To" field shows the email address versus the actual
>>>>> name:
>>>>>
>>>>>    sSearch$ = "[To] = 'jake.f***@bademail.com'"
>>>>>
>>>>>    Set fldFolder =
>>>>> CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)
>>>>>
>>>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>>>
>>>>> Is the above not valid for selecting an email address of
>>>>> jake.f***@bademail.com within the Sent Items folder? If not, what is
>>>>> the proper way to do it? Can you show an example? I have tried the
>>>>> above on my system and it does not locate the email address in the
>>>>> Sent Items folder that I know is there.
>>>>>
>>>>> Thanks,
>>>>>
>>>>> JW
>>>>>
>>>>>
>>>>> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
>>>>> news:eFQbPf2hHHA.1048@TK2MSFTNGP04.phx.gbl...
>>>>>> It is just an Outlook property name, as in
>>>>>> MailItem.SenderEmailAddress. Have you actually tried it?
>>>>>> To property in most cases includes both names and addresses and
>>>>>> corresponds to the PR_DISPLAY_TO MAPI property (look at messages with
>>>>>> MFCMAPI or OutlookSpy), so your restriction won't match any messages.
>>>>>>
>>>>>> Dmitry Streblechenko (MVP)
>>>>>> http://www.dimastr.com/
>>>>>> OutlookSpy  - Outlook, CDO
>>>>>> and MAPI Developer Tool
>>>>>>
>>>>>> "Jerry West" <j*@comcast.net> wrote in message
>>>>>> news:132v5rb59ckh43a@news.supernews.com...
>>>>>>> Thank you for your answer. Where does one find a list of these
>>>>>>> "keywords"? For, example SenderEmailAddress or From? Is there a list
>>>>>>> of these keywords anywhere?
>>>>>>>
>>>>>>> Is "To" a valid keyword? I am trying to select emails based on who
>>>>>>> the email was sent to from within the Sent Items folder:
>>>>>>>
>>>>>>>    sSearch$ = "[To] = 'jake.f***@bademail.com'"
>>>>>>>
>>>>>>>    Set fldFolder =
>>>>>>> CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)
>>>>>>>
>>>>>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>>>>>
>>>>>>> The objItemsCollection.Count property is always 0. So I'm wondering
>>>>>>> if "To" is a keyword? If not, what should I be using and where does
>>>>>>> one find these keywords?
>>>>>>>
>>>>>>> Thanks,
>>>>>>>
>>>>>>> JW
>>>>>>>
>>>>>>> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
>>>>>>> news:%230RmY71hHHA.4064@TK2MSFTNGP02.phx.gbl...
>>>>>>>> Use the SenderEmailAddress property in your restriction.
>>>>>>>>
>>>>>>>> Dmitry Streblechenko (MVP)
>>>>>>>> http://www.dimastr.com/
>>>>>>>> OutlookSpy  - Outlook, CDO
>>>>>>>> and MAPI Developer Tool
>>>>>>>>
>>>>>>>> "Jerry West" <j*@comcast.net> wrote in message
>>>>>>>> news:132v35thp7h1jd4@news.supernews.com...
>>>>>>>>> I'm trying to use the .Restrict method to select emails within the
>>>>>>>>> Inbox:
>>>>>>>>>
>>>>>>>>>    sSearch$ = "[From] = 'Jake Parlance'"
>>>>>>>>>
>>>>>>>>>    Set fldFolder =
>>>>>>>>> CRM.O.AppNameSpace.GetDefaultFolder(olFolderInbox)
>>>>>>>>>
>>>>>>>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>>>>>>>
>>>>>>>>> This works just fine if the email in question has in its From
>>>>>>>>> field the name Jake Parlance. But if I only know Jake Parlance's
>>>>>>>>> email address then it would fail:
>>>>>>>>>
>>>>>>>>> sSearch$ = "[From] = 'jparla***@fake.email.com'"
>>>>>>>>>
>>>>>>>>> I assume it fails because the email address is "resolved" to the
>>>>>>>>> person's actual name. I'd like to be able to search using only the
>>>>>>>>> email address without needing to know the person's name. Is there
>>>>>>>>> a way to do this? I tried:
>>>>>>>>>
>>>>>>>>> sSearch$ = "[E-mail] = 'jparla***@fake.email.com'"
>>>>>>>>>
>>>>>>>>> This did not work because I assume "[E-mail]" is not a "keyword"?
>>>>>>>>> Is it possible to search using email only?
>>>>>>>>>
>>>>>>>>> Also, where does one find a list of all the "keywords", like
>>>>>>>>> "[From]"?
>>>>>>>>>
>>>>>>>>> Thanks!
>>>>>>>>>
>>>>>>>>> JW
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
25 Apr 2007 11:14 PM
Jerry West
The PR_DISPLAY_TO field shows: 'jake.f***@bademail.com'

So it shows the single quote at the beginning of the name and at the end of
the name. So is this not an exact match to that?:

set RestrItems = Folder.Items.Restrict("[To] = 'jake.f***@bademail.com'")

I find it worthy to note that this issue on occurs with the Sent Items
folder. I have no trouble on the other folders I tried. There has to be some
significance to this clue.

JW

Show quote
"Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
news:%23z0$Ux4hHHA.2368@TK2MSFTNGP04.phx.gbl...
> "which has in its To property the email address of
> jake.f***@bademail.com" - this is not what your code does, your code
> restricts on the *exact* match (which is different from "contains").
> Are you sure there are no other characters in the To property? Such as
> single quotes? Look at a matching message with OutlookSpy (click IMessage
> button). What do you see in PR_DISPLAY_TO?
>
> Dmitry Streblechenko (MVP)
> http://www.dimastr.com/
> OutlookSpy  - Outlook, CDO
> and MAPI Developer Tool
>
> "Jerry West" <j*@comcast.net> wrote in message
> news:132vgud8181ri3a@news.supernews.com...
>>> Can you run it from OutlookSpy? Select a folder where you want to
>>> search, click the "Script Editor" button on the OutlookSpy toolbar,
>>> paste the script, modify the condition appropriately, click Run.
>>
>> set Folder = Application.ActiveExplorer.CurrentFolder
>> set RestrItems = Folder.Items.Restrict("[To] = 'jake.f***@bademail.com'")
>> MsgBox RestrItems.Count
>>
>> Not sure how this was going to be different than what I was doing in VB
>> but I did try it. As in VB, .Count is zero. It fails to return the email
>> which has in its To property the email address of jake.f***@bademail.com.
>>
>> If the To property of the email shows as jake.f***@bademail.com and the
>> VB6 IDE also shows that is what the To property holds then shouldn't my
>> code work?
>>
>> set Folder = Application.ActiveExplorer.CurrentFolder
>> set RestrItems = Folder.Items.Restrict("[To] = 'jake.f***@bademail.com'")
>> MsgBox RestrItems.Count
>>
>> I have placed 5 emails in my Sent Items folder. I tried searching for
>> each one of them. I modified my restrict statement to reflect the value
>> of the To field whether it was an actual email address or the "resolved"
>> name. In no case did the search return a hit. There must be some
>> explanation for this. I am using the above code. I can see within the
>> debug window of the VB IDE that the Sent Items folder has the emails I am
>> searching for in it --yet if fails to return them. What could I be doing
>> wrong? Is there another property I could search upon that would yield the
>> same data as the To property?
>>
>> JW
>>
>> JW
>>
>> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
>> news:OrJ7vf3hHHA.3512@TK2MSFTNGP06.phx.gbl...
>>>I have no problem running the following script
>>>
>>> set Folder = Application.ActiveExplorer.CurrentFolder
>>> set RestrItems = Folder.Items.Restrict("[To] = 'Dmitry Streblechenko'")
>>> MsgBox RestrItems.Count
>>>
>>> Can you run it from OutlookSpy? Select a folder where you want to
>>> search, click the "Script Editor" button on the OutlookSpy toolbar,
>>> paste the script, modify the condition appropriately, click Run.
>>>
>>> Dmitry Streblechenko (MVP)
>>> http://www.dimastr.com/
>>> OutlookSpy  - Outlook, CDO
>>> and MAPI Developer Tool
>>>
>>> "Jerry West" <j*@comcast.net> wrote in message
>>> news:132vbn7ph6evn4d@news.supernews.com...
>>>>I can look at the message in the VB6 IDE. I see that the .To property
>>>>reads jake.f***@bademail.com. No name is included.
>>>>
>>>> What I am trying to do is select a email based on the To property (or
>>>> any property that indicates who the email was sent to).
>>>>
>>>> Since I have one email in the Sent Items folder and because I can see
>>>> that this item's To property value is set at jake.f***@bademail.com I
>>>> setup my search string like so:
>>>>
>>>>    sSearch$ = "[To] = 'jake.f***@bademail.com'"
>>>>
>>>> I then search the Sent Items folder for the email:
>>>>
>>>>    Set fldFolder =
>>>> CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)
>>>>
>>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>>
>>>> Unfortunately, this fails. If the To property, as viewed in the debug
>>>> window of the VB6 IDE, is set at jake.f***@bademail.com then why would
>>>> this code fail?
>>>>
>>>> The SenderEmailAddress property can not be used in this scenario since
>>>> it does not return who the email was sent to. The To property and
>>>> SenderEmailAddress do not correspond.
>>>>
>>>> JW
>>>>
>>>> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
>>>> news:u%23%23Exr2hHHA.392@TK2MSFTNGP06.phx.gbl...
>>>>> No, [To] won't work since you are not including the name (it may or
>>>>> rmay not be there)- look at messages with OutlookSpy. most likely To
>>>>> (and PR_DISPLAY_TO MAPI) will be something like "Jerry West" or "Jerry
>>>>> West <j*@comcast.net>"
>>>>> Do use SenderEmailAddress.
>>>>>
>>>>> Dmitry Streblechenko (MVP)
>>>>> http://www.dimastr.com/
>>>>> OutlookSpy  - Outlook, CDO
>>>>> and MAPI Developer Tool
>>>>>
>>>>> "Jerry West" <j*@comcast.net> wrote in message
>>>>> news:132v88otfh1gff7@news.supernews.com...
>>>>>>>> as in MailItem.SenderEmailAddress. Have you actually tried it?
>>>>>>
>>>>>> Yes, it worked great.
>>>>>>
>>>>>>>> To property in most cases includes both names and addresses
>>>>>>
>>>>>> So then the code I show should work, right? I checked the email and I
>>>>>> see that the "To" field shows the email address versus the actual
>>>>>> name:
>>>>>>
>>>>>>    sSearch$ = "[To] = 'jake.f***@bademail.com'"
>>>>>>
>>>>>>    Set fldFolder =
>>>>>> CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)
>>>>>>
>>>>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>>>>
>>>>>> Is the above not valid for selecting an email address of
>>>>>> jake.f***@bademail.com within the Sent Items folder? If not, what is
>>>>>> the proper way to do it? Can you show an example? I have tried the
>>>>>> above on my system and it does not locate the email address in the
>>>>>> Sent Items folder that I know is there.
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>> JW
>>>>>>
>>>>>>
>>>>>> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
>>>>>> news:eFQbPf2hHHA.1048@TK2MSFTNGP04.phx.gbl...
>>>>>>> It is just an Outlook property name, as in
>>>>>>> MailItem.SenderEmailAddress. Have you actually tried it?
>>>>>>> To property in most cases includes both names and addresses and
>>>>>>> corresponds to the PR_DISPLAY_TO MAPI property (look at messages
>>>>>>> with MFCMAPI or OutlookSpy), so your restriction won't match any
>>>>>>> messages.
>>>>>>>
>>>>>>> Dmitry Streblechenko (MVP)
>>>>>>> http://www.dimastr.com/
>>>>>>> OutlookSpy  - Outlook, CDO
>>>>>>> and MAPI Developer Tool
>>>>>>>
>>>>>>> "Jerry West" <j*@comcast.net> wrote in message
>>>>>>> news:132v5rb59ckh43a@news.supernews.com...
>>>>>>>> Thank you for your answer. Where does one find a list of these
>>>>>>>> "keywords"? For, example SenderEmailAddress or From? Is there a
>>>>>>>> list of these keywords anywhere?
>>>>>>>>
>>>>>>>> Is "To" a valid keyword? I am trying to select emails based on who
>>>>>>>> the email was sent to from within the Sent Items folder:
>>>>>>>>
>>>>>>>>    sSearch$ = "[To] = 'jake.f***@bademail.com'"
>>>>>>>>
>>>>>>>>    Set fldFolder =
>>>>>>>> CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)
>>>>>>>>
>>>>>>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>>>>>>
>>>>>>>> The objItemsCollection.Count property is always 0. So I'm wondering
>>>>>>>> if "To" is a keyword? If not, what should I be using and where does
>>>>>>>> one find these keywords?
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>>
>>>>>>>> JW
>>>>>>>>
>>>>>>>> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
>>>>>>>> news:%230RmY71hHHA.4064@TK2MSFTNGP02.phx.gbl...
>>>>>>>>> Use the SenderEmailAddress property in your restriction.
>>>>>>>>>
>>>>>>>>> Dmitry Streblechenko (MVP)
>>>>>>>>> http://www.dimastr.com/
>>>>>>>>> OutlookSpy  - Outlook, CDO
>>>>>>>>> and MAPI Developer Tool
>>>>>>>>>
>>>>>>>>> "Jerry West" <j*@comcast.net> wrote in message
>>>>>>>>> news:132v35thp7h1jd4@news.supernews.com...
>>>>>>>>>> I'm trying to use the .Restrict method to select emails within
>>>>>>>>>> the Inbox:
>>>>>>>>>>
>>>>>>>>>>    sSearch$ = "[From] = 'Jake Parlance'"
>>>>>>>>>>
>>>>>>>>>>    Set fldFolder =
>>>>>>>>>> CRM.O.AppNameSpace.GetDefaultFolder(olFolderInbox)
>>>>>>>>>>
>>>>>>>>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>>>>>>>>
>>>>>>>>>> This works just fine if the email in question has in its From
>>>>>>>>>> field the name Jake Parlance. But if I only know Jake Parlance's
>>>>>>>>>> email address then it would fail:
>>>>>>>>>>
>>>>>>>>>> sSearch$ = "[From] = 'jparla***@fake.email.com'"
>>>>>>>>>>
>>>>>>>>>> I assume it fails because the email address is "resolved" to the
>>>>>>>>>> person's actual name. I'd like to be able to search using only
>>>>>>>>>> the email address without needing to know the person's name. Is
>>>>>>>>>> there a way to do this? I tried:
>>>>>>>>>>
>>>>>>>>>> sSearch$ = "[E-mail] = 'jparla***@fake.email.com'"
>>>>>>>>>>
>>>>>>>>>> This did not work because I assume "[E-mail]" is not a "keyword"?
>>>>>>>>>> Is it possible to search using email only?
>>>>>>>>>>
>>>>>>>>>> Also, where does one find a list of all the "keywords", like
>>>>>>>>>> "[From]"?
>>>>>>>>>>
>>>>>>>>>> Thanks!
>>>>>>>>>>
>>>>>>>>>> JW
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
25 Apr 2007 11:54 PM
Dmitry Streblechenko
Yep, single quotes are not any different from any other character; you must
include them in your restriction.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy  - Outlook, CDO
and MAPI Developer Tool

Show quote
"Jerry West" <j*@comcast.net> wrote in message
news:132vo6gob14kb27@news.supernews.com...
> The PR_DISPLAY_TO field shows: 'jake.f***@bademail.com'
>
> So it shows the single quote at the beginning of the name and at the end
> of the name. So is this not an exact match to that?:
>
> set RestrItems = Folder.Items.Restrict("[To] = 'jake.f***@bademail.com'")
>
> I find it worthy to note that this issue on occurs with the Sent Items
> folder. I have no trouble on the other folders I tried. There has to be
> some significance to this clue.
>
> JW
>
> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
> news:%23z0$Ux4hHHA.2368@TK2MSFTNGP04.phx.gbl...
>> "which has in its To property the email address of
>> jake.f***@bademail.com" - this is not what your code does, your code
>> restricts on the *exact* match (which is different from "contains").
>> Are you sure there are no other characters in the To property? Such as
>> single quotes? Look at a matching message with OutlookSpy (click IMessage
>> button). What do you see in PR_DISPLAY_TO?
>>
>> Dmitry Streblechenko (MVP)
>> http://www.dimastr.com/
>> OutlookSpy  - Outlook, CDO
>> and MAPI Developer Tool
>>
>> "Jerry West" <j*@comcast.net> wrote in message
>> news:132vgud8181ri3a@news.supernews.com...
>>>> Can you run it from OutlookSpy? Select a folder where you want to
>>>> search, click the "Script Editor" button on the OutlookSpy toolbar,
>>>> paste the script, modify the condition appropriately, click Run.
>>>
>>> set Folder = Application.ActiveExplorer.CurrentFolder
>>> set RestrItems = Folder.Items.Restrict("[To] =
>>> 'jake.f***@bademail.com'")
>>> MsgBox RestrItems.Count
>>>
>>> Not sure how this was going to be different than what I was doing in VB
>>> but I did try it. As in VB, .Count is zero. It fails to return the email
>>> which has in its To property the email address of
>>> jake.f***@bademail.com.
>>>
>>> If the To property of the email shows as jake.f***@bademail.com and the
>>> VB6 IDE also shows that is what the To property holds then shouldn't my
>>> code work?
>>>
>>> set Folder = Application.ActiveExplorer.CurrentFolder
>>> set RestrItems = Folder.Items.Restrict("[To] =
>>> 'jake.f***@bademail.com'")
>>> MsgBox RestrItems.Count
>>>
>>> I have placed 5 emails in my Sent Items folder. I tried searching for
>>> each one of them. I modified my restrict statement to reflect the value
>>> of the To field whether it was an actual email address or the "resolved"
>>> name. In no case did the search return a hit. There must be some
>>> explanation for this. I am using the above code. I can see within the
>>> debug window of the VB IDE that the Sent Items folder has the emails I
>>> am searching for in it --yet if fails to return them. What could I be
>>> doing wrong? Is there another property I could search upon that would
>>> yield the same data as the To property?
>>>
>>> JW
>>>
>>> JW
>>>
>>> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
>>> news:OrJ7vf3hHHA.3512@TK2MSFTNGP06.phx.gbl...
>>>>I have no problem running the following script
>>>>
>>>> set Folder = Application.ActiveExplorer.CurrentFolder
>>>> set RestrItems = Folder.Items.Restrict("[To] = 'Dmitry Streblechenko'")
>>>> MsgBox RestrItems.Count
>>>>
>>>> Can you run it from OutlookSpy? Select a folder where you want to
>>>> search, click the "Script Editor" button on the OutlookSpy toolbar,
>>>> paste the script, modify the condition appropriately, click Run.
>>>>
>>>> Dmitry Streblechenko (MVP)
>>>> http://www.dimastr.com/
>>>> OutlookSpy  - Outlook, CDO
>>>> and MAPI Developer Tool
>>>>
>>>> "Jerry West" <j*@comcast.net> wrote in message
>>>> news:132vbn7ph6evn4d@news.supernews.com...
>>>>>I can look at the message in the VB6 IDE. I see that the .To property
>>>>>reads jake.f***@bademail.com. No name is included.
>>>>>
>>>>> What I am trying to do is select a email based on the To property (or
>>>>> any property that indicates who the email was sent to).
>>>>>
>>>>> Since I have one email in the Sent Items folder and because I can see
>>>>> that this item's To property value is set at jake.f***@bademail.com I
>>>>> setup my search string like so:
>>>>>
>>>>>    sSearch$ = "[To] = 'jake.f***@bademail.com'"
>>>>>
>>>>> I then search the Sent Items folder for the email:
>>>>>
>>>>>    Set fldFolder =
>>>>> CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)
>>>>>
>>>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>>>
>>>>> Unfortunately, this fails. If the To property, as viewed in the debug
>>>>> window of the VB6 IDE, is set at jake.f***@bademail.com then why would
>>>>> this code fail?
>>>>>
>>>>> The SenderEmailAddress property can not be used in this scenario since
>>>>> it does not return who the email was sent to. The To property and
>>>>> SenderEmailAddress do not correspond.
>>>>>
>>>>> JW
>>>>>
>>>>> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
>>>>> news:u%23%23Exr2hHHA.392@TK2MSFTNGP06.phx.gbl...
>>>>>> No, [To] won't work since you are not including the name (it may or
>>>>>> rmay not be there)- look at messages with OutlookSpy. most likely To
>>>>>> (and PR_DISPLAY_TO MAPI) will be something like "Jerry West" or
>>>>>> "Jerry West <j*@comcast.net>"
>>>>>> Do use SenderEmailAddress.
>>>>>>
>>>>>> Dmitry Streblechenko (MVP)
>>>>>> http://www.dimastr.com/
>>>>>> OutlookSpy  - Outlook, CDO
>>>>>> and MAPI Developer Tool
>>>>>>
>>>>>> "Jerry West" <j*@comcast.net> wrote in message
>>>>>> news:132v88otfh1gff7@news.supernews.com...
>>>>>>>>> as in MailItem.SenderEmailAddress. Have you actually tried it?
>>>>>>>
>>>>>>> Yes, it worked great.
>>>>>>>
>>>>>>>>> To property in most cases includes both names and addresses
>>>>>>>
>>>>>>> So then the code I show should work, right? I checked the email and
>>>>>>> I see that the "To" field shows the email address versus the actual
>>>>>>> name:
>>>>>>>
>>>>>>>    sSearch$ = "[To] = 'jake.f***@bademail.com'"
>>>>>>>
>>>>>>>    Set fldFolder =
>>>>>>> CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)
>>>>>>>
>>>>>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>>>>>
>>>>>>> Is the above not valid for selecting an email address of
>>>>>>> jake.f***@bademail.com within the Sent Items folder? If not, what is
>>>>>>> the proper way to do it? Can you show an example? I have tried the
>>>>>>> above on my system and it does not locate the email address in the
>>>>>>> Sent Items folder that I know is there.
>>>>>>>
>>>>>>> Thanks,
>>>>>>>
>>>>>>> JW
>>>>>>>
>>>>>>>
>>>>>>> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
>>>>>>> news:eFQbPf2hHHA.1048@TK2MSFTNGP04.phx.gbl...
>>>>>>>> It is just an Outlook property name, as in
>>>>>>>> MailItem.SenderEmailAddress. Have you actually tried it?
>>>>>>>> To property in most cases includes both names and addresses and
>>>>>>>> corresponds to the PR_DISPLAY_TO MAPI property (look at messages
>>>>>>>> with MFCMAPI or OutlookSpy), so your restriction won't match any
>>>>>>>> messages.
>>>>>>>>
>>>>>>>> Dmitry Streblechenko (MVP)
>>>>>>>> http://www.dimastr.com/
>>>>>>>> OutlookSpy  - Outlook, CDO
>>>>>>>> and MAPI Developer Tool
>>>>>>>>
>>>>>>>> "Jerry West" <j*@comcast.net> wrote in message
>>>>>>>> news:132v5rb59ckh43a@news.supernews.com...
>>>>>>>>> Thank you for your answer. Where does one find a list of these
>>>>>>>>> "keywords"? For, example SenderEmailAddress or From? Is there a
>>>>>>>>> list of these keywords anywhere?
>>>>>>>>>
>>>>>>>>> Is "To" a valid keyword? I am trying to select emails based on who
>>>>>>>>> the email was sent to from within the Sent Items folder:
>>>>>>>>>
>>>>>>>>>    sSearch$ = "[To] = 'jake.f***@bademail.com'"
>>>>>>>>>
>>>>>>>>>    Set fldFolder =
>>>>>>>>> CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)
>>>>>>>>>
>>>>>>>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>>>>>>>
>>>>>>>>> The objItemsCollection.Count property is always 0. So I'm
>>>>>>>>> wondering if "To" is a keyword? If not, what should I be using and
>>>>>>>>> where does one find these keywords?
>>>>>>>>>
>>>>>>>>> Thanks,
>>>>>>>>>
>>>>>>>>> JW
>>>>>>>>>
>>>>>>>>> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
>>>>>>>>> news:%230RmY71hHHA.4064@TK2MSFTNGP02.phx.gbl...
>>>>>>>>>> Use the SenderEmailAddress property in your restriction.
>>>>>>>>>>
>>>>>>>>>> Dmitry Streblechenko (MVP)
>>>>>>>>>> http://www.dimastr.com/
>>>>>>>>>> OutlookSpy  - Outlook, CDO
>>>>>>>>>> and MAPI Developer Tool
>>>>>>>>>>
>>>>>>>>>> "Jerry West" <j*@comcast.net> wrote in message
>>>>>>>>>> news:132v35thp7h1jd4@news.supernews.com...
>>>>>>>>>>> I'm trying to use the .Restrict method to select emails within
>>>>>>>>>>> the Inbox:
>>>>>>>>>>>
>>>>>>>>>>>    sSearch$ = "[From] = 'Jake Parlance'"
>>>>>>>>>>>
>>>>>>>>>>>    Set fldFolder =
>>>>>>>>>>> CRM.O.AppNameSpace.GetDefaultFolder(olFolderInbox)
>>>>>>>>>>>
>>>>>>>>>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>>>>>>>>>
>>>>>>>>>>> This works just fine if the email in question has in its From
>>>>>>>>>>> field the name Jake Parlance. But if I only know Jake Parlance's
>>>>>>>>>>> email address then it would fail:
>>>>>>>>>>>
>>>>>>>>>>> sSearch$ = "[From] = 'jparla***@fake.email.com'"
>>>>>>>>>>>
>>>>>>>>>>> I assume it fails because the email address is "resolved" to the
>>>>>>>>>>> person's actual name. I'd like to be able to search using only
>>>>>>>>>>> the email address without needing to know the person's name. Is
>>>>>>>>>>> there a way to do this? I tried:
>>>>>>>>>>>
>>>>>>>>>>> sSearch$ = "[E-mail] = 'jparla***@fake.email.com'"
>>>>>>>>>>>
>>>>>>>>>>> This did not work because I assume "[E-mail]" is not a
>>>>>>>>>>> "keyword"? Is it possible to search using email only?
>>>>>>>>>>>
>>>>>>>>>>> Also, where does one find a list of all the "keywords", like
>>>>>>>>>>> "[From]"?
>>>>>>>>>>>
>>>>>>>>>>> Thanks!
>>>>>>>>>>>
>>>>>>>>>>> JW
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
26 Apr 2007 12:16 AM
Jerry West
I need to add an additional ' character? So you are saying I need to change
the search string to look like this:

set RestrItems = Folder.Items.Restrict("[To] = ''jake.f***@bademail.com''")

When I try that I get an error. Must the ' character be escaped somehow?

JW

Show quote
"Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
news:uNjk4S5hHHA.4588@TK2MSFTNGP02.phx.gbl...
> Yep, single quotes are not any different from any other character; you
> must include them in your restriction.
>
> Dmitry Streblechenko (MVP)
> http://www.dimastr.com/
> OutlookSpy  - Outlook, CDO
> and MAPI Developer Tool
>
> "Jerry West" <j*@comcast.net> wrote in message
> news:132vo6gob14kb27@news.supernews.com...
>> The PR_DISPLAY_TO field shows: 'jake.f***@bademail.com'
>>
>> So it shows the single quote at the beginning of the name and at the end
>> of the name. So is this not an exact match to that?:
>>
>> set RestrItems = Folder.Items.Restrict("[To] = 'jake.f***@bademail.com'")
>>
>> I find it worthy to note that this issue on occurs with the Sent Items
>> folder. I have no trouble on the other folders I tried. There has to be
>> some significance to this clue.
>>
>> JW
>>
>> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
>> news:%23z0$Ux4hHHA.2368@TK2MSFTNGP04.phx.gbl...
>>> "which has in its To property the email address of
>>> jake.f***@bademail.com" - this is not what your code does, your code
>>> restricts on the *exact* match (which is different from "contains").
>>> Are you sure there are no other characters in the To property? Such as
>>> single quotes? Look at a matching message with OutlookSpy (click
>>> IMessage button). What do you see in PR_DISPLAY_TO?
>>>
>>> Dmitry Streblechenko (MVP)
>>> http://www.dimastr.com/
>>> OutlookSpy  - Outlook, CDO
>>> and MAPI Developer Tool
>>>
>>> "Jerry West" <j*@comcast.net> wrote in message
>>> news:132vgud8181ri3a@news.supernews.com...
>>>>> Can you run it from OutlookSpy? Select a folder where you want to
>>>>> search, click the "Script Editor" button on the OutlookSpy toolbar,
>>>>> paste the script, modify the condition appropriately, click Run.
>>>>
>>>> set Folder = Application.ActiveExplorer.CurrentFolder
>>>> set RestrItems = Folder.Items.Restrict("[To] =
>>>> 'jake.f***@bademail.com'")
>>>> MsgBox RestrItems.Count
>>>>
>>>> Not sure how this was going to be different than what I was doing in VB
>>>> but I did try it. As in VB, .Count is zero. It fails to return the
>>>> email which has in its To property the email address of
>>>> jake.f***@bademail.com.
>>>>
>>>> If the To property of the email shows as jake.f***@bademail.com and the
>>>> VB6 IDE also shows that is what the To property holds then shouldn't my
>>>> code work?
>>>>
>>>> set Folder = Application.ActiveExplorer.CurrentFolder
>>>> set RestrItems = Folder.Items.Restrict("[To] =
>>>> 'jake.f***@bademail.com'")
>>>> MsgBox RestrItems.Count
>>>>
>>>> I have placed 5 emails in my Sent Items folder. I tried searching for
>>>> each one of them. I modified my restrict statement to reflect the value
>>>> of the To field whether it was an actual email address or the
>>>> "resolved" name. In no case did the search return a hit. There must be
>>>> some explanation for this. I am using the above code. I can see within
>>>> the debug window of the VB IDE that the Sent Items folder has the
>>>> emails I am searching for in it --yet if fails to return them. What
>>>> could I be doing wrong? Is there another property I could search upon
>>>> that would yield the same data as the To property?
>>>>
>>>> JW
>>>>
>>>> JW
>>>>
>>>> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
>>>> news:OrJ7vf3hHHA.3512@TK2MSFTNGP06.phx.gbl...
>>>>>I have no problem running the following script
>>>>>
>>>>> set Folder = Application.ActiveExplorer.CurrentFolder
>>>>> set RestrItems = Folder.Items.Restrict("[To] = 'Dmitry
>>>>> Streblechenko'")
>>>>> MsgBox RestrItems.Count
>>>>>
>>>>> Can you run it from OutlookSpy? Select a folder where you want to
>>>>> search, click the "Script Editor" button on the OutlookSpy toolbar,
>>>>> paste the script, modify the condition appropriately, click Run.
>>>>>
>>>>> Dmitry Streblechenko (MVP)
>>>>> http://www.dimastr.com/
>>>>> OutlookSpy  - Outlook, CDO
>>>>> and MAPI Developer Tool
>>>>>
>>>>> "Jerry West" <j*@comcast.net> wrote in message
>>>>> news:132vbn7ph6evn4d@news.supernews.com...
>>>>>>I can look at the message in the VB6 IDE. I see that the .To property
>>>>>>reads jake.f***@bademail.com. No name is included.
>>>>>>
>>>>>> What I am trying to do is select a email based on the To property (or
>>>>>> any property that indicates who the email was sent to).
>>>>>>
>>>>>> Since I have one email in the Sent Items folder and because I can see
>>>>>> that this item's To property value is set at jake.f***@bademail.com I
>>>>>> setup my search string like so:
>>>>>>
>>>>>>    sSearch$ = "[To] = 'jake.f***@bademail.com'"
>>>>>>
>>>>>> I then search the Sent Items folder for the email:
>>>>>>
>>>>>>    Set fldFolder =
>>>>>> CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)
>>>>>>
>>>>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>>>>
>>>>>> Unfortunately, this fails. If the To property, as viewed in the debug
>>>>>> window of the VB6 IDE, is set at jake.f***@bademail.com then why
>>>>>> would this code fail?
>>>>>>
>>>>>> The SenderEmailAddress property can not be used in this scenario
>>>>>> since it does not return who the email was sent to. The To property
>>>>>> and SenderEmailAddress do not correspond.
>>>>>>
>>>>>> JW
>>>>>>
>>>>>> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
>>>>>> news:u%23%23Exr2hHHA.392@TK2MSFTNGP06.phx.gbl...
>>>>>>> No, [To] won't work since you are not including the name (it may or
>>>>>>> rmay not be there)- look at messages with OutlookSpy. most likely To
>>>>>>> (and PR_DISPLAY_TO MAPI) will be something like "Jerry West" or
>>>>>>> "Jerry West <j*@comcast.net>"
>>>>>>> Do use SenderEmailAddress.
>>>>>>>
>>>>>>> Dmitry Streblechenko (MVP)
>>>>>>> http://www.dimastr.com/
>>>>>>> OutlookSpy  - Outlook, CDO
>>>>>>> and MAPI Developer Tool
>>>>>>>
>>>>>>> "Jerry West" <j*@comcast.net> wrote in message
>>>>>>> news:132v88otfh1gff7@news.supernews.com...
>>>>>>>>>> as in MailItem.SenderEmailAddress. Have you actually tried it?
>>>>>>>>
>>>>>>>> Yes, it worked great.
>>>>>>>>
>>>>>>>>>> To property in most cases includes both names and addresses
>>>>>>>>
>>>>>>>> So then the code I show should work, right? I checked the email and
>>>>>>>> I see that the "To" field shows the email address versus the actual
>>>>>>>> name:
>>>>>>>>
>>>>>>>>    sSearch$ = "[To] = 'jake.f***@bademail.com'"
>>>>>>>>
>>>>>>>>    Set fldFolder =
>>>>>>>> CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)
>>>>>>>>
>>>>>>>>    Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
>>>>>>>>
>>>>>>>> Is the above not valid for selecting an email address of
>>>>>>>> jake.f***@bademail.com within the Sent Items folder? If not, what
>>>>>>>> is the proper way to do it? Can you show an example? I have tried
>>>>>>>> the above on my system and it does not locate the email address in
>>>>>>>> the Sent Items folder that I know is there.
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>>
>>>>>>>> JW
>>>>>>>>
>>>>>>>>
>>>>>>>> "Dmitry Streblechenko" <dmi***@dimastr.com> wrote in message
>>>>>>>> news:eFQbPf2hHHA.1048@TK2MSFTNGP04.phx.gbl...
>>>>>>>>> It is just an Outlook property name, as in
>>>>>>>>> MailItem.SenderEmailAddress. Have you actually tried it?
>>>>>>>>> To property in most cases includes both names and addresses and
>>>>>>>>> corresponds to the PR_DISPLAY_TO MAPI property (look at messages
>>>>>>>>> with MFCMAPI or OutlookSpy), so your restriction won't match any
>>>>>>>>> messages.
>>>>>>>>>
>>>>>>>>> Dmitry Streblechenko (MVP)
>>>>>>>>> http://www.dimastr.com/
>>>>>>>>> OutlookSpy  - Outlook, CDO
>>>>>>>>> and MAPI Developer Tool
>>>>>>>>>
>>>>>>>>> "Jerry West" <j*@comcast.net> wro