Outlook Selection object

  • Thread starter Thread starter Michael Tissington
  • Start date Start date
M

Michael Tissington

I'm seeing a strange issue with the Outlook Selection Object.
It seems that once I reference an item in the Selection object then that
object remains open until I release the Selection object.

For example (in brief)

Set Selections = ActiveExplorer.Selection

For Each Contact in Selections
Debug .Print Contact.FullName
Contact.Close
Set Contact = Nothing
' at this point the contact is still open
Next

Set Selections = Nothing ' this closes all the referenced Contacts

Is this by design or am I missing something .....

How do I force the Contact to be closed?
 
Have you tried leaving out the Close statement completely? If you aren't
opening it, you shouldn't need to close it.
 
Yes, I added the close to see if it would fix it ....

After playing a little more what seems to work is if I don't cache the
Selection object

For X = 1 To ActiveExplorer.Selections.Count
Set Contact = ActiveExplorer.Selections.Item(X)
Debug .Print Contact.FullName
Contact.Close
Set Contact = Nothing
Next

But this is slow :(

--
Michael Tissington
http://www.oaklodge.com
http://www.tabtag.com
 
Yes, that's a big problem with the Selection collection: once you touch it
(even if you only need a count) it loops through all the items and
initializes them.
A particularly nasty side-effect of this sloppy behavior is that it makes it
extremely easy to run out of the 255 RPC channels/process limit.

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