Two CommandBarButtons that run the same event code

D

DavidE

Hi ,
I create two CommandBarButtons in two seperate projects.I add This buttons
to the standard Command bar. When I click one of them the event runs the code
of the both AddIns. To solve this problem I add the 'OnAction' property on
the creation of the buttons, but it doesn't help, each button runs the code
of the both AddIns .
Here the code :
'The first button :
Private Sub CreateButtons(objInspector As Outlook.Inspector)
On Error Resume Next

'Adding a new menu item and a button to the main menu for any Inspector
' must take a different approach if using Word as email editor.

Dim objCB As Office.CommandBar
Dim strKey As String

Set objCB = m_objInsp.CommandBars("standard")

strKey = CStr(m_intID)
strTag = "This string is unique to this button" & strKey
Set cbbFaxButton = objCB.Controls.Add(Type:=msoControlButton,
Temporary:=True)

With cbbFaxButton
.ToolTipText = "Send fax"
.Tag = strTag
.Style = msoButtonIconAndCaption
.FaceId = 461
.Caption = "fax"
.Visible = True
.OnAction = "<!" & strProgId & ">"
End With

Set objCB = Nothing
Err.Clear

End Sub
**************
The .OnAction property get this value :
<!FaxSystem.fax_Connect>


'*** The second button

Private Sub CreateButtons(objInspector As Outlook.Inspector)
On Error Resume Next

Dim oPic As StdPicture
Dim objCB As Office.CommandBar
Dim strKey As String

Set objCB = objInspector.CommandBars("standard")

strKey = CStr(m_intID)
strTag = "This string is unique to this button" & strKey
Set cbbButton = objCB.Controls.Add(Type:=msoControlButton,
Temporary:=True)

With cbbButton
.ToolTipText = "Send to Mrkv"
.Tag = strTag
.Style = msoButtonIconAndCaption
.Caption = "Mrkv"
.Visible = True
.OnAction = "<!" & strProgId & ">"

End With

Set objCB = Nothing
Set objOutAddIn = Nothing
Err.Clear

End Sub

**********
The .OnAction property get this value :
<!Merkava.Mrkv_Connect>

How can I solve this problem ?

Thanks,
David
 
K

Ken Slovak - [MVP - Outlook]

Both projects should have unique ProgID's and you need to make sure that
both buttons have unique Tag properties. I would check and make sure that's
the case. If the Inspector is the first one it looks to me like both would
have a Tag of 1. You would need a unique string to add to that.

Addin 1:

strTag = "Addin1" & CStr(m_intID)

Addin 2:
strTag = "Addin2" & CStr(m_intID)
 
D

DavidE

Thanks Ken.
The problem was with the Tag property that was the same in both commands.
Sorry for the late response.I wasn't here.

David
 

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