Inspector Button Click?

B

Brian McCullough

Hello,

I have a VB6 COM Addin in which I am placing a custom button on the MailItem
Inspector window. I am creating a similar button on the Standard toolbar of
the Outlook application as well. Both the custom button on the Outlook
toolbar and the custom button on the MailItem Inspector window have similar,
but not the same functionality and should look the same. In an effort to
reduce the lines of code needed to create the buttons, I have put this code
in a module (.bas). In this module I have a method defined that accepts a
CommandBar reference to which I add the button. I am calling this same
method to create the look/feel of the button.

The problem is that when I press the button on an Inspector window, the code
for the Outlook button is running in addition to the code for the button on
the Inspector. In addition, the Inspector code is running for each open
Mail Item Inspector!?!?!?!

What do I need to do to ensure that only the code for the Inspector which I
clicked the button runs???


Here is my method that is used to create my button(s):


Public Function CreateJunkEmailCommandButton(ByVal objCommandBar As
Office.CommandBar, ByVal strAddInProgID As String, ByVal
lngBeforeButtonIndex) As Office.CommandBarButton
'method-level variable declarations
Dim objCommandBarButton As Office.CommandBarButton

'error handling should bubble up and be handled in calling procedure


'get a reference to the Junk Email button if it already exists, if not,
it will be created in just a bit.
Set objCommandBarButton =
objCommandBar.FindControl(Tag:=JUNK_EMAIL_COMMAND_BUTTON_TAG)

'If the button doesn't already exist, create it.
If objCommandBarButton Is Nothing Then
If lngBeforeButtonIndex > 0 Then
'add the button in the specified location
Set objCommandBarButton =
objCommandBar.Controls.Add(Type:=msoControlButton, Temporary:=True,
Before:=lngBeforeButtonIndex)
Else
'otherwise, add the button to the end of the toolbar
Set objCommandBarButton =
objCommandBar.Controls.Add(Type:=msoControlButton, Temporary:=True)
End If

With objCommandBarButton
'define the properties for the Junk Email button
.Style = msoButtonIconAndCaption
.Parameter = JUNK_EMAIL_COMMAND_BUTTON_TAG
.Tag = JUNK_EMAIL_COMMAND_BUTTON_TAG
.Caption = JUNK_EMAIL_COMMAND_BUTTON_CAPTION
.ToolTipText = JUNK_EMAIL_COMMAND_BUTTON_TOOLTIP

'load the picture from the resource file
.Picture = LoadResPicture(101, 0)

'determine what to do when the button is clicked
.OnAction = "<!" & strAddInProgID & ">"

'position the button
.BeginGroup = True
End With
End If

'ensure the button and associated CommandBar are visible to the user
objCommandBarButton.Visible = True
objCommandBar.Visible = True

'return the CommandBarButton so that calling procedure can set
'a reference to it to handle it's events, such as OnClick
Set CreateJunkEmailCommandButton = objCommandBarButton

End Function
 
K

Ken Slovak - [MVP - Outlook]

Assign a unique Tag property to every button you create. Otherwise you get
one click event for each button as a button is pressed.

That applies even more when you are handling multiple open Inspectors and
using an Inspector wrapper. You want to have each Inspector maintain its own
click event handler so you don't get one button press firing click events in
every open Inspector. A unique Tag is again the answer.
 
B

Brian McCullough

Thanks Ken!!

Yeah, I created Inspector Wrapper classes: MailInspector and
MailInspectorCollection. The MailInspectorCollection class is just a
wrapper around the collection functionality (Add, Remove, For Each support,
etc). The MailInspector includes a reference to the Inspector object and
handles the events for the Inspector (such as it's Close event) and my
custom button's click event. So there is a MailInspector object added to
the MailInspectorCollection each time an Inspector is opened in Outlook.

I am still using my generic 'create button' procedure, but I am now
modifying the Tag property of the button by appending the MailItem's EntryID
value to the end of it. I would think this would be a unique value for
each MailItem, and therefore, make my Tag value unique for each MailItem
Inspector opened. I have it working right now with this, but do you see any
problems with using the EntryID in the Tag?

Thanks!

Brian
 
K

Ken Slovak - [MVP - Outlook]

It can change if an item is moved or deleted in an Exchange mailbox. It
would remain the same under those circumstances in a PST file, but the
behavior is store provider dependent.

In my wrappers I assign a Key property, based on a number that gets
incremented for each new Inspector or Explorer during an Outlook session. So
each Key int is unique. I add the Key string to a unique string I use for
each button and that provides a unique Tag value.

I think the Inspector wrapper sample on my Web site shows that technique.
 

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