Hi!
I'm working with an outlook add-in for Outlook 2003 and running into
some problems with contact items. For example, if I open Contact1 and
click on my add-in button I get the right information on my form for
Contact1. When I open Contact2 and click on the add-in button I get
information regarding contact2. However, when I go back
to Contact1 and click on the add-in button, I get information for
Contact2.
Dim WithEvents m_olContactItem As Outlook.ContactItem
'Creation fo the add-in button
Dim l_oCI As Outlook.ContactItem
Dim l_cbStandard As CommandBar
l_oCI = CType(i_oItem, Outlook.ContactItem)
l_cbStandard = l_oCI.GetInspector.CommandBars("Standard")
Dim WithEvents CBBSearchContact As CommandBarButton
'Add button to toolbar
CBBSearchContact =
CType(l_cbStandard.Controls.Add(Type:=MsoControlType.msoControlButton,
_
Parameter:="Get Contact", Before:=3, Temporary:=True),
CommandBarButton)
Private Sub m_olInspectors_NewInspector(ByVal i_oInspector As
Outlook.Inspector) Handles m_olInspectors.NewInspector
Try
m_olInspector = CType(i_oInspector, Outlook.InspectorClass)
If TypeOf i_oInspector.CurrentItem Is Outlook.MailItem Then
'Must cast to MailItemClass due to "ambiguous name" problem
' m_olMailItem = CType(i_oInspector.CurrentItem,
Outlook.MailItemClass)
ElseIf TypeOf i_oInspector.CurrentItem Is Outlook.PostItem Then
m_olPostItem = CType(i_oInspector.CurrentItem,
Outlook.PostItem)
ElseIf TypeOf i_oInspector.CurrentItem Is Outlook.AppointmentItem
Then
m_olAppointmentItem = CType(i_oInspector.CurrentItem,
Outlook.AppointmentItem)
ElseIf TypeOf i_oInspector.CurrentItem Is Outlook.ContactItem
Then
m_olContactItem = CType(i_oInspector.CurrentItem,
Outlook.ContactItem)
ElseIf TypeOf i_oInspector.CurrentItem Is Outlook.DistListItem
Then
m_olDistListItem = CType(i_oInspector.CurrentItem,
Outlook.DistListItem)
ElseIf TypeOf i_oInspector.CurrentItem Is Outlook.JournalItem
Then
m_olJournalItem = CType(i_oInspector.CurrentItem,
Outlook.JournalItem)
ElseIf TypeOf i_oInspector.CurrentItem Is Outlook.TaskItem Then
m_olTaskItem = CType(i_oInspector.CurrentItem,
Outlook.TaskItem)
End If
Catch ex As SystemException
MsgBox(m_sDEFAULT_ERROR_MESSAGE & "Source = " & m_sModName &
".m_olInspectors_NewInspector. Message = " & ex.Message,
MsgBoxStyle.Exclamation, Err.Source)
End Try
End Sub
My code for my add-in click event is as follows:
Private Sub CBBSearchContact_Click(ByVal Ctrl As
Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean)
Handles CBBSearchContact.Click
Dim frmAnyForm As Windows.Forms.Form
Try
'send m_olContactItem is created
Dim contactSearch As New ContactFrame(m_olContactItem)
contactSearch .ShowDialog()
Catch ex As System.Exception
MsgBox("Error:" & ex.Message, MsgBoxStyle.Exclamation,
m_sADDIN_NAME)
End Try
End Sub
Any help would be appreciated.
Thanks in advance.
/Lori
Sue Mosher [MVP-Outlook] - 16 Dec 2005 21:12 GMT
If your add-in needs to be able to handle multiple items open in their own windows, you'll need a wrapper class. See http://www.outlookcode.com/d/vb.htm#wrapper for links.
FYI, there is a newsgroup specifically for Outlook add-in issues "down the hall" at microsoft.public.outlook.program_addins or, via web interface, at http://www.microsoft.com/office/community/en-us/default.mspx?dg=microsoft.public
.outlook.program_addins

Signature
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx
> Hi!
>
[quoted text clipped - 86 lines]
>
> /Lori
Lori - 20 Dec 2005 11:29 GMT
Thanks again Sue! I will try that solution.
/Lori