use of restrict function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to write a filter to use in a restict statement to identify
contacts whose subject is missing (i have no idea how this happened, but it
did, and it creates problems with the outlook address book).
the filter myitems.restrict("[subject] = " & vbnullstring) returns no items,
although several have their subject missing.
there are hundreds of affected contacts, so I want to be able to initially
obtain a collection of all such contacts (ie subject missing) so i can then
place a further restriction based on the first letter of the last name. this
way i can deal with the problem in alphabetical "chunks" to save downtime.
eg my items = myitems.restrict( - your suggestion here)
myitems = myitems.restrict("[Last Name] < " & strInitial)
for each item in myitems
myitem.subject = myitem.full name
myitem.save
next item
this way each successive routine will only have to process those items whose
initial letter of the last name is less than "strInitial" and who have the
missing subject.
will only process
 
See if this works:
myitems.restrict("[subject] = ''")

That is 2 single quotes followed by a double quote.
 
Thanks Ken, but it did not work.
I assume that functions such as len() etc are unusable in this context.
Any other ideas?

Ken Slovak - said:
See if this works:
myitems.restrict("[subject] = ''")

That is 2 single quotes followed by a double quote.




aross said:
I am trying to write a filter to use in a restict statement to identify
contacts whose subject is missing (i have no idea how this happened, but it
did, and it creates problems with the outlook address book).
the filter myitems.restrict("[subject] = " & vbnullstring) returns no items,
although several have their subject missing.
there are hundreds of affected contacts, so I want to be able to initially
obtain a collection of all such contacts (ie subject missing) so i can then
place a further restriction based on the first letter of the last name. this
way i can deal with the problem in alphabetical "chunks" to save downtime.
eg my items = myitems.restrict( - your suggestion here)
myitems = myitems.restrict("[Last Name] < " & strInitial)
for each item in myitems
myitem.subject = myitem.full name
myitem.save
next item
this way each successive routine will only have to process those items whose
initial letter of the last name is less than "strInitial" and who have the
missing subject.
will only process
 
You can't use functions in a restriction or filter.

It works here. I selected a folder with 3 items in it with no subject, the
total count of items in the folder is 47. Running the code below returns a
value of 3 and I can access any of those 3 items from the restricted
collection.

Sub RestrictNullSubject()
Dim oItems As Outlook.Items
Dim oFiltered As Outlook.Items

Set oItems = Application.ActiveExplorer.CurrentFolder.Items
Set oFiltered = oItems.Restrict("[Subject] = ''")
Debug.Print oFiltered.Count
End Sub
 
Thanks Ken, it works fine if I create a contact and then delete the subject.
However, it does not detect my client's contacts in their Public Folders who
have nothing in the subject field. They have 5-6 users in the office, and the
same number using laptops and synchronising with the contacts folder.
I can loop thru them all, and use something like
If len(cItem.Subject) = 0 then etc
but this involves testing all 15,000 of them, and time is of the essence
since the absence of a Subject seems to prevent the Contacts' Names coming up
in the Outlook Address Book.
If the absence of anything in the subject field is not detected by your
suggested code, what am I looking for? (If you have any suggestions how this
could happen in the first place it might give me a clue)
Thanks again for taking the trouble to help.

Ken Slovak - said:
You can't use functions in a restriction or filter.

It works here. I selected a folder with 3 items in it with no subject, the
total count of items in the folder is 47. Running the code below returns a
value of 3 and I can access any of those 3 items from the restricted
collection.

Sub RestrictNullSubject()
Dim oItems As Outlook.Items
Dim oFiltered As Outlook.Items

Set oItems = Application.ActiveExplorer.CurrentFolder.Items
Set oFiltered = oItems.Restrict("[Subject] = ''")
Debug.Print oFiltered.Count
End Sub





aross said:
Thanks Ken, but it did not work.
I assume that functions such as len() etc are unusable in this context.
Any other ideas?
 
I have no idea how it could happen, the first thing to find out is exactly
what's in the Subject. Get a few of those items that have no subject and
play with them. See what's what. I didn't delete any subjects BTW, I just
used my Drafts folder where some items are stored that never did have a
Subject entered. So I didn't do anything special.

I'd also see if the restriction works if tried on a folder with fewer items.
Try copying some of the items, maybe 100 or so from the target folder to any
dummy folder you create. Then see if the restriction works.

Another alternative would be to use OutlookSpy (www.dimastr.com) to look at
those items by selecting them one at a time, clicking on the IMsg button and
seeing what values are actually stored in the subject (PR_SUBJECT).

For working with that large a data set I'd probably skip using the Outlook
object model myself. I'd use CDO 1.21 code which is an order of magnitude
faster with a MessageFilter set on that Messages collection or for even
faster speed a MAPITable with filter using Redemption
(www.dimastr.com/redemption).
 
Thanks again, Ken - I installed OutlookSpy and took a look at some of the
problem contacts using the IMessage tool. The problem Contacts have no
entries for PR_Subject or PR_Subject_Prefix !?! (ie The Property Tag is not
listed.)
I guess that might explain why the restrict statement would not work, since
we are asking the code to find items with a zero-length subject, but the
items we are looking for do not have a subject field at all.
Meanwhile, I wrote a vb.net app which restricts the items by first letter of
Last Name, and then loops thru all the returned items and tests if
len(cItem.Subject) = 0, if so the Subject is set to cItem.FullName and saved.
I tested it on the letter Z, and it worked fine. (My knowledge of CDO is
poor, and I may not have time to get up to speed.)
If you have any suggestions where I might look for clues as to why the
subject is missing in its entirety, they would be greatly appreciated. I can
run my vb.net app in the evenings to get thru the contacts one letter at a
time, but I am concerned to prevent the problem recurring.
Thanks again.
 
In that case I can see why the restriction is failing.

A contact item without PR_SUBJECT or PR_NORMALIZED_SUBJECT would certainly
be unusual however. Using a MAPITable and filter I could see testing for the
existence of PR_SUBJECT and returning all rows where it didn't exist, but
that's not an Outlook object model solution to your problem.

Many fields don't actually exist until they are initialized with some value,
but when I just created a new contact and saved it with no data at all in it
the item does show PR_SUBJECT in OutlookSpy. In any case those are usually
the ones that are listed in bold at the top of the property list in
OutlookSpy, and at least here have 0x80nn type tags.

The only thing I can think of is to ask if you are using some sort of synch
program with a PDA or something else that might have removed various
standard properties from items?
 
I have today been informed by the client that their new hardware support
company performed some permission resets on the exchange server, following
the methodology outlined in KB article 270905. Apparently, the server (Win2K
SBS) crashed during this procedure. Could this have caused some corruption to
a % of the contacts, causing them to "lose" their subject property?
Meanwhile I am ploughing my way thru the contacts using the .net app to put
them to rights.
However, the Outlook Address Book still does not show any contacts in the
list (so they cannot "pick" a contact), although it now fills the list as
soon as they enter a letter in the <Type Name or Select from List> box. Do
you think this problem is likely to resolve itself once all the contacts have
a proper subject?
Thanks again for your continuing help.
 
It's possible I suppose, I've never seen contacts with no subject however so
it's purely guesswork. It doesn't sound like a very competent support outfit
if they crashed the client's server though.

Generally the subject for a contact is the FullName. So any that don't have
a subject you can just set to FullName and you should be OK.

Is the folder(s) where the contacts are located set as Outlook address
books? That is the most common reason they wouldn't show up in an Address
Book dialog. Right-click on the contacts folder in the folder list or
navigation pane, select Properties and go to the Outlook Address Book tab.
Make sure the checkbox to show the folder as an AB is checked. Also, Outlook
must have the address book service installed for contacts to be seen as a
virtual address book.
 
Hi Ken
Just a short note to say that i finally got thru all the contacts, resetting
their subject - one of then had an unresolved synchronisation conflict from 2
years ago, which seemed to stop the code running - and now the full list of
contacts appears in the Outlook Address Book!
So the problem is solved, however I still don't understand why it happened
in the first place. Could it be something to do with the unresolved conflict,
coupled with the server crash?
Anyway, thanks for your support.
 
I doubt it, I've had conflicts and never seen the subject field just
disappear. I really have no idea what caused it since I've never heard of it
happening before. Sorry. Let's just hope it doesn't happen again :)
 
Back
Top