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);
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);