strange occurance, why does this happen??
ho there
i have a control whihc is added to the menu bar in outlook, but when i change to a non mail folder , the control is dupplicated.
its very strange bexcause the routine which creates control in the first place isnt fired (on_connection) .
why does this happen
many thanks
jamie
Re: strange occurance, why does this happen??
Jamie
In the procedure you use to create/add the control, your first step should be to call the procedure you use to remove the control. That way you will never get duplication.
Re: strange occurance, why does this happen??
i have tried this but i still get the control duplicated
this is very wierd. here is my code whihc ceates the control.
VB Code:
Dim WithEvents oApp As Outlook.Application
Private Sub addMenuBarControls()
' This subroutine is called when Add-in is connected
' to by the host application.
' Get the Application object for Outlook.
Dim objApp As Outlook.Application
Set objApp = Outlook.Application
Dim testcontrol As Office.CommandBarControl
On Error Resume Next
Set testcontrol = objApp.ActiveExplorer.CommandBars.item("Menu bar").controls.item("&Iscent Evidence")
If testcontrol Is Nothing Then
Else
testcontrol.Delete
End If
Set omycontrol = objApp.ActiveExplorer.CommandBars.item("Menu Bar").controls.Add(Type:=msoControlPopup, Temporary:=True)
omycontrol.Caption = "&Iscent Evidence"
Set oAboutMenuBar = omycontrol.controls.Add(Type:=msoControlButton, Temporary:=True, Before:=1)
oAboutMenuBar.Caption = "&About"
oAboutMenuBar.Enabled = True
Set oHelpMenuBar = omycontrol.controls.Add(Type:=msoControlButton, Temporary:=True, Before:=1)
oHelpMenuBar.Caption = "&Help"
oHelpMenuBar.Enabled = True
Set oExtractMenuBar = omycontrol.controls.Add(Type:=msoControlButton, Temporary:=True, Before:=1)
oExtractMenuBar.Caption = "&Extract"
oExtractMenuBar.Enabled = True
Set oVerifyMenuBar = omycontrol.controls.Add(Type:=msoControlButton, Temporary:=True, Before:=1)
oVerifyMenuBar.Caption = "&Verify Document"
oVerifyMenuBar.Enabled = True
Set oSealandSendMenuBar = omycontrol.controls.Add(Type:=msoControlButton, Temporary:=True, Before:=1)
oSealandSendMenuBar.Caption = "&Seal and Send"
oSealandSendMenuBar.Enabled = True
Set objApp = Nothing
Set testcontrol = Nothing
End Sub
is this code correct?
i create a local application object within the routinem, is this ok, or should i use the application declared with events?
does this make any difference
cheers
jamie
Re: strange occurance, why does this happen??
hi there
heres the code my class. it has been stripped down of everything else, yet the control still gets duplicated on folder swotch
does anyone know why?
Code:
Implements IDTExtensibility2
Private Sub IDTExtensibility2_OnAddInsUpdate( _
custom() As Variant)
' Use this subroutine when Add-ins are updated.
'MsgBox "OnAddInsUpdate called"
End Sub
' Use this subroutine when the host app is shutting down.
' You should persist or destroy your objects in this
' subroutine.
Private Sub IDTExtensibility2_OnBeginShutdown( _
custom() As Variant)
End Sub
Private Sub IDTExtensibility2_OnDisconnection( _
ByVal RemoveMode As _
AddInDesignerObjects.ext_DisconnectMode, _
custom() As Variant)
' This Sub is called when your add-in is
' disconnected from the host.
MsgBox "OnDisconnection called"
End Sub
Private Sub IDTExtensibility2_OnStartupComplete( _
custom() As Variant)
' This Sub is called when the host application has
' completed its startup routines.
'MsgBox "OnStartupComplete called"
End Sub
Private Sub IDTExtensibility2_OnConnection( _
ByVal Application As Object, ByVal ConnectMode As _
AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, custom() As Variant)
addMenuBarControls
End Sub
'==========================================================================================
'BUILD CONTROLS METHODS
Private Sub addMenuBarControls()
' This subroutine is called when Add-in is connected
' to by the host application.
' Get the Application object for Outlook.
Dim objApp As Outlook.Application
Set objApp = Outlook.Application
MsgBox "Menu being added"
Dim testcontrol As Office.CommandBarControl
On Error Resume Next
Set testcontrol = objApp.ActiveExplorer.CommandBars.Item("Menu bar").Controls.Item("&New Control")
If testcontrol Is Nothing Then
Else
testcontrol.Delete
End If
Dim lPosition As Long
Dim ctlControl As CommandBarControl
'Determine the Position of the Help MENU
For Each ctlControl In objApp.ActiveExplorer.CommandBars.Item("Menu Bar").Controls
If ctlControl.Caption = "&Help" Then
lPosition = ctlControl.Index
Exit For
End If
Next
Set omycontrol = objApp.ActiveExplorer.CommandBars.Item("Menu Bar").Controls.Add(msoControlPopup, , , lPosition, True)
omycontrol.Caption = "&Test"
Set oAboutMenuBar = omycontrol.Controls.Add(msoControlButton, , , , True)
oAboutMenuBar.Caption = "&About"
oAboutMenuBar.Enabled = True
Set oHelpMenuBar = omycontrol.Controls.Add(msoControlButton, , , , True)
oHelpMenuBar.Caption = "&Help"
oHelpMenuBar.Enabled = True
Set oExtractMenuBar = omycontrol.Controls.Add(msoControlButton, , , , True)
oExtractMenuBar.Caption = "&Other"
oExtractMenuBar.Enabled = True
Set oVerifyMenuBar = omycontrol.Controls.Add(msoControlButton, , , , True)
oVerifyMenuBar.Caption = "&Verify"
oVerifyMenuBar.Enabled = True
Set oSealandSendMenuBar = omycontrol.Controls.Add(msoControlButton, , , , True)
oSealandSendMenuBar.Caption = "&Send"
oSealandSendMenuBar.Enabled = True
Set objApp = Nothing
Set testcontrol = Nothing
End Sub
if someone could have a go on their pc, and then try switching folders, to see what happen. i have tested on teo and the control gets duplicated
many thannks
Jamie