Addin Buttons not working

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

Hi I have created an addin for outlook in VB6.0. Each
time a new inspector is opened I check to see if it is a
mailitem and if so I add a command bar and button to the
inspector window. The button works fine until another
inspector window is opened and then it stops working and
will only work for the new inspector window. I know this
happens becuase when the NewInspector event fires I set
the command bar button to the new inspector and therefore
will only work for the newest one opened. How do I get
it to still work for all the other inspectors that are
already opened.

Private Sub ins_NewInspector(ByVal inspector As
Outlook.inspector)

Dim cb As CommandBar

On Error Resume Next
If TypeName(inspector.CurrentItem) = "MailItem" Then
If Not inspector.IsWordMail Then
Set cb = inspector.CommandBars("FilePro Bar")
If cb Is Nothing Then
Set cb = inspector.CommandBars.Add("FilePro
Bar", msoBarTop, , True)
Set cbAttachDoc = cb.Controls.Add(1, , , ,
True)
With cbAttachDoc
.Caption = "&Attach document"
.FaceId = 271
.Style = msoButtonIconAndCaption
.ToolTipText = "Attach document from
FilePro"
End With
End If
cb.Visible = True
End If
End If
End Sub
 
You need to use an Inspector wrapper and declare your buttons in the wrapper
class using a unique Tag property for each button so each fires an
individual and unique Click event handler. This is a similar concept to the
Explorer wrapper class and collection used in the ItemsCB COM addin sample
(VB 6) on the Resources page at www.microeye.com

I use code something like the following. This example only shows a MailItem
declared WithEvents, to handle other item types you'd add additional
declarations. In the code that adds the class to the wrapper collection you
would check for the type of the item in the new Inspector
(Inspector.CurrentItem) and add or not add the class based on that,
depending if you wanted to handle the events for that item type.

The following code is a skeleton for an
Inspector class module, that gets put into a collection when NewInspector
fires and is removed from the collection when the Inspector is closed.
Handling the collection is similar to how it's done in the Explorer wrapper
code in ItemsCB.

VB 6 code:

Private WithEvents m_objInsp As Outlook.Inspector
Private WithEvents m_objMail As Outlook.MailItem

Private m_lngID As Long

Private Sub Class_Initialize()
On Error Resume Next

Set m_objInsp = Nothing
Set m_objMail = Nothing
End Sub

Private Sub Class_Terminate()
On Error Resume Next

Set m_objInsp = Nothing
Set m_objMail = Nothing
End Sub

Public Property Let Inspector(objInspector As Outlook.Inspector)
On Error Resume Next

Set m_objInsp = objInspector
Set m_objMail = objInspector.CurrentItem
End Property

Public Property Get Inspector() As Outlook.Inspector
On Error Resume Next

Set Inspector = m_objInsp
End Property

Public Property Let Key(lngID As Long)
On Error Resume Next

m_lngID = lngID
End Property

Public Property Get Key() As Long
On Error Resume Next

Key = m_lngID
End Property

'*********************************************************************
'Event Procedure: m_objInsp_Close()
'Destroy Inspector object in InspWrap
'*********************************************************************
Private Sub m_objInsp_Close()
On Error Resume Next

basOutlInsp.KillInsp m_lngID, Me
Set m_objInsp = Nothing

If Err <> 0 Then
AddInErr Err, "clsInspWrap", "m_objInsp_Close"
End If
End Sub

You can now add button creation to this code, remembering to use a unique
Tag property for each button in each Inspector.
 
Ken thanks for your reply.

I have used your advice and made and Inspector wrapper
and now the buttons work for all open inspectors.

Thanks very much once again.
 
Back
Top