save prompt and form region

S

sd

Hello
I've VSTO SE Addin for OL2007.I've adjoined form region to standard
Appointment form.I've placed AX Ctrl built using vb6 on that form
region.It prompts me for save even though I didn't make any change.The
AX Ctrl contains 2 combos.In combo change & click I'm calling
AddModifyUserProp which adds or modifies userprop value.B'coz of
addition/Modification of userprop values it may be prompting for
save,but once userprop gets added it should not prompt for save.but I
always get save prompt whenever I open existing item ,changes combo
contents & for save prompt I says no ,reopens same item & closes the
item without any change.Now though no change,it prompts me for
save.Below is the code-
AX Ctrl-
Public Sub AddModifyUserProp(ByVal PropName As String, ByVal PropValue
As String)
Set ObjAppointmentItem = ActiveInspector.CurrentItem
If Not ObjAppointmentItem Is Nothing Then
Dim userProperty As Outlook.userProperty
Set userProperty =
ObjAppointmentItem.UserProperties.Find(PropName, True)
If userProperty Is Nothing Then
Set userProperty =
ObjAppointmentItem.UserProperties.Add(PropName, olText, True)
End If
userProperty.Value = PropValue
Set ObjAppointmentItem = Nothing
End If
End Sub

ComposeAppoinmentFormRegionWrapper.vb -
Class ComposeAppoinmentFormRegionWrapper
Inherits BaseFormRegionWrapper
Private m_Application As Outlook.Application
Private WithEvents m_Items As Outlook.Items
Shadows WithEvents FormRegion As Outlook.FormRegion
Shadows WithEvents UserForm As Forms.UserForm
Shadows WithEvents Item As Outlook.AppointmentItem
Private WithEvents CtlRegion As MyAXCtrl
Public Sub New(ByVal region As Outlook.FormRegion, ByVal application
As Outlook.Application)
m_Application = application
Me.Item = region.Item
Me.FormRegion = region
Me.UserForm = CType(FormRegion.Form, Forms.UserForm)
InitializeControls()
End Sub
Private Sub InitializeControls()
CtlRegion =
DirectCast(UserForm.Controls.Item("MyAXCtrl1"),MyAXCtrl)
DisplayUserProperties 'assigns values to combos on
AXCtrl ,In AXCtrl while assigning values to
combo,AddModifyUserProperties()
'is avoided initially by a flag ,which is reset so after displaying
values to combo ,AddModifyUserProperties() gets invoked if combo is
changed
End Sub
Private Sub item_Write(ByRef cancel As Boolean) Handles Item.Write
'retrieves AXCtrl combo values & writes them to database.
End sub
Private Sub FormRegion_Close() Handles FormRegion.Close
If Not (m_Items Is Nothing) Then
m_Items = Nothing
End If
If Not CtlRegion Is Nothing Then CtlRegion = Nothing
If Not UserForm Is Nothing Then UserForm = Nothing
If Not FormRegion Is Nothing Then FormRegion = Nothing
If Not m_Application Is Nothing Then m_Application =
Nothing
RaiseClose()
End Sub

BaseFormRegionWrapper.vb
MustInherit Class BaseFormRegionWrapper
Implements IDisposable
Private Disposed As Boolean = False
Protected Item As Object
Protected WithEvents FormRegion As Outlook.FormRegion
Protected WithEvents UserForm As Forms.UserForm
Public Event Close As EventHandler
Protected Sub RaiseClose()
RaiseEvent Close(Me, EventArgs.Empty)
End Sub
Protected Overrides Sub Finalize()
Me.Dispose(False)
End Sub
Public Overloads Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
Protected Overloads Sub Dispose(ByVal disposeManagedResources As
Boolean)
If Not Me.Disposed Then
If disposeManagedResources Then
Item = Nothing
End If
If Not (FormRegion Is Nothing) Then
Marshal.ReleaseComObject(FormRegion)
FormRegion = Nothing
End If
If Not (UserForm Is Nothing) Then
Marshal.ReleaseComObject(UserForm)
UserForm = Nothing
End If
Disposed = True
End If
End Sub

Thanks
 
K

Ken Slovak - [MVP - Outlook]

If I understand your question, any changes to any property or user property,
or adding a new user property to an item will of course dirty the item
therefore prompting to save when the item is being closed. You can avoid
that by not adding or changing any properties in items or by calling Save()
on the item yourself.
 
S

sd

Thanks ken,
but the save prompt comes when I close Outlook not when I close the
item.The item gets closed without any prompt.Adding a userprop. should
ask for save for the first time ,once the prop. is added the save
prompt will not come.If this is correct then why save prompt comes
again?I checked customprop. change event also but invain.
 
K

Ken Slovak - [MVP - Outlook]

That would indicate that somehow a reference is being kept alive for that
item, the release of that reference is allowing the item to be disposed of
and that's what's causing the prompt to save on closing Outlook. I don't
know if the reference is being kept alive by your ActiveX control or by some
other code in your addin but that has to be it.

If your control is changing settings in controls that are bound to Outlook
properties then changes to the controls would also change the Outlook
properties.

Probably the best thing would be to track your usage of all references to
the items in question and make sure you are disposing of them. To get
finality on your releasing the item you might want to use
Marshal.ReleaseComObject() on the item and then possibly even call
GC.Collect() followed by GC.WaitForPendingFinalizers().
 

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