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] =
''(e-mail address removed)''")
When I try that I get an error. Must the ' character be escaped somehow?
JW
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
The PR_DISPLAY_TO field shows: '(e-mail address removed)'
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] =
'(e-mail address removed)'")
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
"which has in its To property the email address of
(e-mail address removed)" - 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
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] =
'(e-mail address removed)'")
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
(e-mail address removed).
If the To property of the email shows as (e-mail address removed) 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] =
'(e-mail address removed)'")
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
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
I can look at the message in the VB6 IDE. I see that the .To
property reads (e-mail address removed). 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
(e-mail address removed) I setup my search string like so:
sSearch$ = "[To] = '(e-mail address removed)'"
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 (e-mail address removed) 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
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 <
[email protected]>"
Do use SenderEmailAddress.
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
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] = '(e-mail address removed)'"
Set fldFolder =
CRM.O.AppNameSpace.GetDefaultFolder(olFolderSentMail)
Set objItemsCollection = fldFolder.Items.Restrict(sSearch$)
Is the above not valid for selecting an email address of
(e-mail address removed) 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
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
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] = '(e-mail address removed)'"
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
Use the SenderEmailAddress property in your restriction.
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
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] = '(e-mail address removed)'"
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] = '(e-mail address removed)'"
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