Find or Restrict for Contacts where property is blank

  • Thread starter Thread starter Shona Helstrom
  • Start date Start date
S

Shona Helstrom

Hi,

I'm trying to find a list of all contact in a folder where the
property is blank

The following is trying to use the restrict method

dim myItems as Outlook.Items

myItems = folder.items.restrict("[Hobby] = ''")

but this returns nothing, even though i know that the property doesn't
contain anything

I've also tried the find method but that didn't work either.

Any help would greatly be appreciated.

thanks in advance
shona
 
Outlook doesn't add that field or many others to items unless the field is
populated with some value. So your restriction is failing because the field
doesn't exist. In MAPI you could test for the field existing a part of a
MAPI table filter but you cannot do that using the Outlook object model.

What I usually do in cases like that where I need to use Outlook object
model filtering is to initialize the fields I want to test on to "" (null
string) or some other appropriate value for the field data type and then I
can use the filter.
 
Thanks for your answer Ken.

I only picked Hobby as a property but what I'm really trying to do is
filter on contacts that don't have emails address so that I don't get
that security message.

But I also noticied something strange. If Outlook doesn't add the
field to an item if it is note populated why does it return all items
if I say field <> "":

if I say :
myItems = folder.items.restrict("[Email1Address] = ''")
I get nothing

If I say:
myItems = folder.items.restrict("[Email1Address] <> ''")
I get all the items even though I know that none of the contacts in
the folder have email addresses populated. And if i debug.writeline
the properties out for a contact where I know it doesn't have the
email1address populated i get
""
 
That's just the way it works. Are you sure the restriction is actually in
effect in those cases? No errors or anything? If the restriction fails you'd
get the complete Items collection.
 
Hi Ken,

I've wrapped it in a try-catch so it doesn't error out. Although that
is an unusual way to handle restriction failures to return everything.
Oh well. We've told our users that they will see the security msg
and just to allow the app to access.

Thanks for answering my questions.
Shona
 
Back
Top