Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming Add-Ins / March 2008

Tip: Looking for answers? Try searching our database.

save prompt and form region

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sd - 18 Mar 2008 10:10 GMT
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
Ken Slovak - [MVP - Outlook] - 18 Mar 2008 14:03 GMT
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.

Signature

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

> Hello
> I've VSTO SE Addin for OL2007.I've adjoined form region to standard
[quoted text clipped - 104 lines]
>
> Thanks
sd - 25 Mar 2008 14:58 GMT
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.
Ken Slovak - [MVP - Outlook] - 25 Mar 2008 15:10 GMT
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().

Signature

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

> 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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.