Ryan C Price

I have an application with a custom appointment form. Everything seemed to be working fine until my client noticed that when sync'ing their Pocket PC, their appointment times weren't always changing on the PDA.

After two days of investigating, I have discovered that if I create an appointment with my custom form, and then try and change the times of the appointment, while still in the same Outlook session, then the time change does not propagate to OWA (Outlook Web Access), or to PDAs (which essentially also use OWA). Any other changes to the Body, Subject, etc. all propagate fine; just the times don't.

So I have created a new (much simplified) AddIn to reproduce the problem. I have VS2005 with SP1 and with VSTO SE, running on a virtual Windows XP machine with Outlook 2003 SP3.

To reproduce my problem, first reproduce my add-in:

1) Create a new VB Add-In for Outlook 2003.

2) Add a new Form called Form1, and add 4 controls:

a) StartTime (a DateTimePicker, use a custom format that includes date and time)

b) EndTime (ditto)

c) Subject (a TextBox)

d) Body (a TextBox; I made mine MultiLine)

3) Replace the Add-In code with the following:

Code Block

Public Class ThisAddIn
Private WithEvents inspectors As Outlook.Inspectors

Private Sub ThisAddIn_Startup( _
ByVal sender As Object, _
ByVal e As System.EventArgs _
) Handles Me.Startup

inspectors = Application.Inspectors

End Sub

Private Sub NewInspector( _
ByVal Inspector As Microsoft.Office.Interop.Outlook.Inspector _
) Handles inspectors.NewInspector

Dim appointment As Outlook.AppointmentItem = _
TryCast(Inspector.CurrentItem, Outlook.AppointmentItem)

If appointment IsNot Nothing Then
Dim aw As New AppointmentWrapper(appointment)
aw.Show()
End If

End Sub
End Class

Public Class AppointmentWrapper
Private WithEvents _appointment As Outlook.AppointmentItem
Private WithEvents myAppt As Form1

Public Sub New(ByVal appointment As Outlook.AppointmentItem)
_appointment = appointment
myAppt = New Form1()
myAppt.Subject.Text = _appointment.Subject
myAppt.Body.Text = _appointment.Body
myAppt.StartTime.Value = _appointment.Start
myAppt.EndTime.Value = _appointment.End
End Sub

Public Sub Show()
myAppt.Show()
End Sub

Private Sub Appointment_Open( _
ByRef Cancel As Boolean _
) Handles _appointment.Open

Cancel = True

End Sub

Private Sub myAppt_FormClosed( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.FormClosedEventArgs _
) Handles myAppt.FormClosed

_appointment.Subject = myAppt.Subject.Text
_appointment.Body = myAppt.Body.Text
_appointment.Start = myAppt.StartTime.Value
_appointment.End = myAppt.EndTime.Value
_appointment.Close(Outlook.OlInspectorClose.olPromptForSave)
_appointment = Nothing

End Sub
End Class

and then run it.

To see the problem in action do the following, without restarting Outlook:

1) Open your calendar and create a new appointment, it will load your custom form.

2) Fill in the subject and body, and set the times if you like.

3) Close the form and save when prompted.

4) Using OWA, check that the appointment is there, with the times you specified.

5) Back in Outlook, move the appointment. Or better still, open again and change the times, subject and body.

6) Back in OWA, refresh your calendar and open the appointment.

If you get the same results as me, then your OWA appoinment will have the updated subject and body, but not the updated times.

If you restart Outlook and move the appointment, everything then seems fine.

Can anybody help me Even if someone else can reproduce this problem and tell me I'm not crazy, it'll help!

Thanks in advance,

Ryan




Re: Visual Studio Tools for Office More Information: Appointment time changes not propagating to OWA when appointment created with VSTO form ?!?!?!

Ryan C Price

Still trying to find an answer, but have more evidence. It would seem that when Outlook is in 'Cached' mode, the add-in works as intended, but with 'Cached Mode' turned off (online mode only), the problem surfaces.

This is being investigated by Microsoft, but I would nonetheless appreciate any input....

I can supply a complete VS2005 solution if anyone wants it (one that's a little more sophisticated than the included code)

/Ryan






Re: Visual Studio Tools for Office More Information: Appointment time changes not propagating to OWA when appointment created with VSTO form ?!?!?!

Ryan C Price

Microsoft have been able to supply me with a workaround for the problem, should anyone else encounter something similar.

Essentially, you need to fully release the COM object when you close the appointment. If you want to continue working with the appointment, you need to close the appointment, release the COM object and then re-acquire the appointment using its EntryID.

Code Block

' _appointment is the Form-level Outlook.Appointment object.

Dim entryId As String

Dim app As Outlook.Application

entryId = _appointment.EntryId

app = _appointment.Application

_appointment.Close(Outlook.OlInspectorClose.olSave)

Marshal.FinalReleaseComObject(_appointment)

_appointment = Nothing

_appointment = app.GetNamespace("MAPI").GetItemFromID(entryId)

Marshal.FinalReleaseComObject(app)

app = Nothing