Custom Contact Form requires Outlook restart

D

ddsfdfs

I have a Com-addin that is using a custom contact form which is published as
the default for a contact folder. The com-addin is designed so that when
users to drag in their own contacts into this form and will update it to use
the new custom contact form by changing its MessageClass. This works kind
of.

When I drag the contact to the folder the MessageClass changes to reflect
using the new contact form (IPM.Contact.SharedContacts) however when I open
the form it is still using the default contact form. If I exit Outlook and
reopen the same contact it now correctly uses the custom form.

Here is the code that I use to change the MessageClass.
Private Sub m_olExplorer_BeforeFolderSwitch(ByVal NewFolder As Object,
ByRef Cancel As Boolean) Handles m_olExplorer.BeforeFolderSwitch
Dim oFolder As Outlook.MAPIFolder
On Error Resume Next
oFolder = NewFolder

If oFolder.Name = "Upload Contacts" Then

Dim NewMC As String = "IPM.Contact.SharedContacts"

Dim i As Integer
Dim AllItems As Outlook.Items = oFolder.Items
Dim NumItems As Integer = oFolder.Items.Count
Dim CurItem As Outlook.ContactItem
' Loop through all of the items in the folder

For i = 1 To NumItems
CurItem = AllItems.Item(i)

' Test to see if the Message Class needs to be changed
If CurItem.MessageClass <> NewMC Then
' Change the Message Class
CurItem.MessageClass = NewMC
' Save the changed item
CurItem.Save()
End If
Next

End If
End Sub
 
D

ddsfdfs

To the other members of the newsgroup there was a little more to it than
just setting CurItem=nothing which is due to the fact I'm using VB.Net to
create the add-in for Outlook 2003. When I set CurItem=Nothing it didn't
solve the problem meaning that I was still forced to restart Outlook to see
the new form applied. After a bit more research I discovered that the .Net
framework doesn't immediately clean up the COM objects right away so I had
to initiate the garbage collection with the following lines:
GC.Collect()

GC.WaitForPendingFinalizers()



That did the trick. Thanks Tim
 

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