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
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