Outlook Contact Add-in - Cancelling a Write Option still closes pa

G

GordonS

We are using Outlook 2007 with an add-in form region built in Visual Studio
2008.

In the inspector wrapper class for our Contact Addin, I attach an event onto
the Write event of the contact item. When I press the Save + Close button on
the Contact window, this event is called, but setting the Cancel flag doesn’t
stop the contact from closing.

This is very important because we have an event sink on the server that
picks up changes and sends them to our SQL Server database for our ASP.Net
application, and we cannot allow invalid data to be sent to it.

I have traced the execution of the code down through Visual Studio 2008 and
when the code drops out of our Write event handler, the next bit of our code
we step into is the FormRegionClosed event handler of our region, then its
Dispose() method. Where is it that directs the logic to close the form – I
have checked all the code behind generated from Visual Studio?

Is there a way to keep our contact form open if our validation on save finds
errors, so that the user has the opportunity to correct them first?

Here are some relevant parts of code that may help you identify the problem:

The Write event handler:

void mobjAppItem_Write(ref bool Cancel)
{
if (!BeforeSaveCleanup())
{
// Cancel doesn't stop a Save + Close button press from
closing, so don't cancel update.
Cancel = true;
m_bHaveSwitchedForm = false;
return;
}
}

The setup code for my events:
((MSOutlook.InspectorEvents_10_Event)mobjInspector).Activate +=
new
Microsoft.Office.Interop.Outlook.InspectorEvents_10_ActivateEventHandler(ContactInspectorWrapper_Activate);
((MSOutlook.InspectorEvents_10_Event)mobjInspector).Close += new
Microsoft.Office.Interop.Outlook.InspectorEvents_10_CloseEventHandler(InspectorWrapper_Close);
((MSOutlook.InspectorEvents_10_Event)mobjInspector).PageChange
+= new
Microsoft.Office.Interop.Outlook.InspectorEvents_10_PageChangeEventHandler(ContactInspectorWrapper_PageChange);

mobjAppItem = (MSOutlook.ContactItem)mobjInspector.CurrentItem;
mobjAppItem.Write += new
MSOutlook.ItemEvents_10_WriteEventHandler(mobjAppItem_Write);
mobjAppItem.BeforeAutoSave += new
Microsoft.Office.Interop.Outlook.ItemEvents_10_BeforeAutoSaveEventHandler(mobjAppItem_BeforeAutoSave);
 
J

Jialiang Ge [MSFT]

Hello GordonS,

In order to cancel the closure of a Contact item, we need to use
ItemEvents_10_Event.Close:
http://msdn.microsoft.com/en-us/lib...nterop.outlook.itemevents_10_event.close.aspx
http://msdn.microsoft.com/en-us/library/aa171213(office.11).aspx

This event is triggered prior to Inspector.Close, and we have a chance to
cancel the closure by setting the Cancel parameter to True.

((Outlook.ItemEvents_10_Event)item).Close += new
Microsoft.Office.Interop.Outlook.ItemEvents_10_CloseEventHandler(ThisItem_Close);

void ThisAddIn_Close(ref bool Cancel)
{
// we perform the check of the contact value here.
// if the check fails, we cancel the closure:
Cancel = true;
}

By the way, the Cancel parameter in the Write event cannot cancel the
closure behavior, please refer to the document for more detail:
http://msdn.microsoft.com/en-us/lib....outlook.itemevents_10_writeeventhandler.aspx

Please try the solution and let me know whether it works for you.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jialiang Ge [MSFT]

Hello GordonS,

I am writing to check the status of the issue on your side. Would you mind
letting me know the result of the suggestions? If you need further
assistance, feel free to let me know. I will be more than happy to be of
assistance.

Have a great day!

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 

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