Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Inspector.Close event is not fired

261 views
Skip to first unread message

Alex K.

unread,
Jan 16, 2007, 10:16:00 AM1/16/07
to
Hi all

I am working on Outlook 2002 AddIn using VB.NET.
Basically, it works, BUT:
I noticed that Inspector's Close event is not fired when user presses "Save
and Close" button, e.g. in Contact form.
Is anybody aware of this issue?
How do I catch the moment an inspector actually closes? I need this to
clean-up/destroy event handlers, otherwise they keep accumulating in memory.

Thank you

Ken Slovak - [MVP - Outlook]

unread,
Jan 16, 2007, 11:50:17 AM1/16/07
to
Catch the Item.Close event also.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Alex K." <Al...@discussions.microsoft.com> wrote in message
news:2B54594E-C93F-4328...@microsoft.com...

Alex K.

unread,
Jan 16, 2007, 12:51:00 PM1/16/07
to
But Microsoft.Office.Interop.Outlook.ContactItem does not have Close event!
That's the problem. There is such event in Outlook VBA but not in Interop.
Does that mean I have to use VB6?

Ken Slovak - [MVP - Outlook]

unread,
Jan 16, 2007, 1:44:08 PM1/16/07
to
All events that use the same name as a method have other ways of getting to
the event. The Item.Close event is available for all items and item types.
In this case it would be ItemEvents_CloseEventHandler.

In C# I'd use something like this:

// at class level
private Outlook.ItemsEvents_Event m_events;
private Outlook.ContactItem m_contact;

// in init code
m_events = (Outlook.ItemEvents_Event)m_contact;
m_events.Close += new Outlook.ItemEvents_CloseEventHandler(m_contact_Close);

// event handler
private void m_contact_Close(ref bool Cancel)
{
// whatever
}

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Alex K." <Al...@discussions.microsoft.com> wrote in message

news:3F611E6D-52B5-43B5...@microsoft.com...

Alex K.

unread,
Jan 16, 2007, 2:30:00 PM1/16/07
to
Ken,
thank you so much! It works!


"Ken Slovak - [MVP - Outlook]" wrote:

Md.A.RaheeM

unread,
Feb 26, 2010, 7:01:01 AM2/26/10
to
Hi Sir..

i tried to use ur code block in C# VS2008...:


// at class level
private Outlook.ItemsEvents_Event m_events;
private Outlook.ContactItem m_contact;

// in init code
m_events = (Outlook.ItemEvents_Event)m_contact;
m_events.Close += new Outlook.ItemEvents_CloseEventHandler(m_contact_Close);

// event handler
private void m_contact_Close(ref bool Cancel)
{
// whatever
}


but i am getting two errors as below:
1) 'Microsoft.Office.Interop.Outlook.ItemsEvents_Event' does not contain a
definition for 'Close' and no extension method 'Close' accepting a first
argument of type 'Microsoft.Office.Interop.Outlook.ItemsEvents_Event' could
be found (are you missing a using directive or an assembly reference?)

2) Cannot implicitly convert type
'Microsoft.Office.Interop.Outlook.ItemEvents_Event' to
'Microsoft.Office.Interop.Outlook.ItemsEvents_Event'. An explicit conversion
exists (are you missing a cast?)

plz help me on this..... by providing solution on how to disable the
default close(x) button of Inspector window
--OR--
let me know how to catch the Item.close event / Inspector.Close Event...


Thanks

Regards
Md.A.RaheeM

Ken Slovak - [MVP - Outlook]

unread,
Feb 26, 2010, 9:07:08 AM2/26/10
to
I'm not sure who you're addressing since the rest of the thread has scrolled
off the server and you don't provide any clues or context. You're also not
providing any information about the Outlook version you're working with.

First of all, if you look at the object browser you will see that the
Inspector.Close() event does not have a Cancel argument. The event cannot be
cancelled. The ContactItem.Close() event (and other item types) does have a
Cancel argument, so if you want to cancel closing the item based on certain
conditions you should be handling that event and not Inspector.Close().

For an item.Close() handler you wouldn't use Outlook.ItemsEvents_Event, but
you could use Outlook.ItemEvents_Event. Note that your code uses ItemsEvents
and the following uses ItemEvents with no "s" in Item.

If you were to use that way of handling ContactItem.Close() you would
instantiate it as follows:

// at class level
private Outlook.ItemEvents_Event _itemEvents = null;

// init code

_itemEvents = (Outlook.ItemEvents_Event)m_contact;

// hook up the ContactItem Close event handler

_itemEvents.Close += new Outlook.ItemEvents_CloseEventHandler(OnItem_Close);


--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com

Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Md.A.RaheeM" <Md.A....@discussions.microsoft.com> wrote in message
news:1045F108-EDB4-4495...@microsoft.com...

0 new messages