catching item open events

J

jillgude

I am writing an Outllook add-in using Visual Basic and CDO. Is there
any way to catch the open events of all items without listening for
each type of item open seperately? I am currently catching the
mailItem_open event, but this does not work for items such as tasks,
contacts, etc. Is there a generic itemOpen_event that gets fired when
any item is openned? Or do I have to catch the open event of
mailItems, ContactItems, AppointmentItems, etc individually?

Thanks!
 
J

jillgude

Thanks! That worked to catch all open events. I now have another
related issue, though. After catching the open event, I redirect the
open. I then need the item that the user clicked on to not open. I
tried calling both of the following methods in the newInspector event.

Inspector.Close olDiscard
Inspector.CurrentItem.Close olDiscard

However neither of these calls seems to work. The item is still
displayed in the new inspector. Is there an eqivalent to the Cancel
variable of the item open event (i.e. is there a way that I can stop
the inspector from displaying the current item)?
 
K

Ken Slovak - [MVP - Outlook]

Is WordMail involved? It sounds like it.

If so you would need to use the equivalent of Inspector.WordEditor (use
Inspector.IsWordMail to see at runtime) and issue a Close command to the
Document represented by WordEditor.

If only 1 Word window is open at that time you might also need to use the
equivalent of Inspector.WordEditor.Application.Quit to get the now empty
Word window to close down.
 
S

Sue Mosher [MVP-Outlook]

Another technique to try is to use the NewInspector event to instantiate WithEvents an object for the item that's opening. You can then catch the item's Open event, which is cancellable.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
J

jillgude

Catching the item open event is the ideal approach. However, I am not
sure what type of item I will be catching, as I wish to catch all
types-- mail, tasks, calendar, etc. Is there anyway listen to an items
events without being exactly sure whicht type of item it is? I was
able to get around catching the item open event, by catching the
newInspector event. I then "canceled" the open event by listening for
the Inspector_Activate event, and immediately closing the inspector.
This isn't ideal, as it cause a quick flash in the item being openned,
but it works.

I am now running into another similar problem though. I also need to
catch the write event, and sometimes prevent the user from updating the
item. Again, I need to do this for all types of items that can be
found in a user's mailbox. I was previously doing this only for
MailItems as well, by catching the Item_Write event. I need a way to
do it for all types of items without having to declare tons of
different item types with events. I have tried using the
items_itemchange event, but this does not seem to work as it occurs
after the write has already taken place. Also, once I catch this
event, I am not sure how to prevent the write anyway. Any suggests?

Thanks for all the help so far!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top