Addhandler not working

D

Dhananjay

Hi all,
I have created one COM-addin in VSTO SE / VB 2005 / Outlook 2003.
Same code works fine when I created the addin for outlook 2007.

My code snippet is as follows

' In general section
Private WithEvents myContact As ContactItem
Private ItemsCollection As Generic.IList(Of Inspector)
Private WithEvents myInspectors As Inspectors

' This is NewInspctors event
Private Sub myInspectors_NewInspector(ByVal Inspector As
Microsoft.Office.Interop.Outlook.Inspector) Handles
myInspectors.NewInspector
AddTrace("Opening New Insp Start")
If ItemsCollection Is Nothing Then
AddTrace("Creating inspectors collection")
ItemsCollection = New Generic.List(Of Inspector)
End If
If
Inspector.CurrentItem.MessageClass.ToUpper.Contains("IPM.CONTACT")
Then
AddTrace("Contact inspector found")
ItemsCollection.Add(Inspector)
AddTrace("Adding handlers")
AddHandler
ItemsCollection(ItemsCollection.IndexOf(Inspector)).Activate,
AddressOf GenericActiveInspector
AddHandler
ItemsCollection(ItemsCollection.IndexOf(Inspector)).Close, AddressOf
GenericCloseInspector
AddTrace("Setting inspectors")
GenericInsp = Inspector
End If
AddTrace("Opening New Insp End")
End Sub

' This is one addhandler
Sub GenericActiveInspector()
AddTrace("Checking active inspector Start")
If Application.ActiveInspector IsNot Nothing Then
GenericInsp = Application.ActiveInspector
End If
Try
If TypeName(GenericInsp.CurrentItem).ToUpper =
"CONTACTITEM" Then
AddTrace("Contact inspector found")
myContact = TryCast(GenericInsp.CurrentItem,
ContactItem)
If myContact IsNot Nothing Then
'MsgBox("contact")
AddTrace("Contact set - Success")
Else
AddTrace("Contact set - Unsuccess")
End If
End If
Catch ex As System.Exception
AddTrace(ex.Message)
End Try
AddTrace("Checking active inspector End")
End Sub

'This is my another handler
Sub GenericCloseInspector()
AddTrace("Closing active inspector Start")
Try
If
TypeName(Application.ActiveInspector.CurrentItem).ToUpper =
"CONTACTITEM" Then
AddTrace("Contact inspector found")
If Application.ActiveInspector Is Nothing Then
AddTrace("ActiveInsp is not Nothing")
RemoveHandler
ItemsCollection(ItemsCollection.IndexOf(Application.ActiveInspector)).Close,
AddressOf GenericCloseInspector
AddTrace("Removed close")
RemoveHandler
ItemsCollection(ItemsCollection.IndexOf(Application.ActiveInspector)).Activate,
AddressOf GenericActiveInspector
AddTrace("Removed activeinsp")

ItemsCollection.RemoveAt(ItemsCollection.IndexOf(Application.ActiveInspector))
myContact = Nothing
Else
AddTrace("ActiveInsp Nothing")
End If
AddTrace("Removed item from collection")
End If
Catch ex As System.Exception
AddTrace("Exception while closing inspector - " &
ex.Message)
MsgBox("Exception while closing inspector - " &
ex.Message, MsgBoxStyle.Critical Or MsgBoxStyle.SystemModal)
End Try
AddTrace("Closing active inspector End ")
End Sub

Now whenever I open any contactitem, I add it to the collection &
whenever I activate any contactitem's inspector, while debugging
control goes to "GenericActiveInspector" method, I set myContact there
& proceed my writing through it.
But whenever I close any contactitem's inspector, my
"GenericCloseInspector" method isn't fired.
So what is the problem for outlook 2003 version.

Thanks in advance,
Dhananjay
 

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