jamielawjen
Jan 25th, 2006, 04:50 AM
hi there.
i am a seasoned developer (though not in office programming or in vb6), but i am writing an addin for outlook 2000+ in vb6
i have a popmenucontrol which i add on_connection. this works fine.
but, i am having a few problems. when you select a different folder (contacts, calendar, journal, tasks) the control is duplicated in the menu bar. it is not calling the addmenubar sub i created. it just creates another control!
anyhow, i need the menu to disappear when a user is in a folder which contains non mailitems.
so i wrtoe the code below, which should loop through and remove any controls on the menu bar with the name 'Jamies control', if the current folders default items arent mailtype. but, when the code runs, it crashes outlook, with a memory problem. this happens everytime, and it happens when the objcontrol.delete method is run
any help would be greatly appreciated, and please, if there is a better way to do this then please let me know
cheers in advance
jamie
Private Sub objexplorer_ViewSwitch()
Dim folder As MAPIFolder
Set folder = Application.ActiveExplorer.CurrentFolder
Dim objCB As Office.CommandBarControls
Dim objControl As Office.CommandBarControl
Set objCB = Application.ActiveExplorer.CommandBars.item("menu bar").controls
If folder.DefaultItemType = olMailItem Then
'remove any controls with the name Jamies Control
For Each objControl In objCB
If objControl.Caption = "&Jamies Control" Then
objControl.Delete
End If
Next
'then we add the new pop up control
addMenuBarControls
Else
For Each objControl In objCB
If objControl.Caption = "&Jamies Control" Then
objControl.Delete
End If
Next
'addMenuBarControls
End If
End Sub
i am a seasoned developer (though not in office programming or in vb6), but i am writing an addin for outlook 2000+ in vb6
i have a popmenucontrol which i add on_connection. this works fine.
but, i am having a few problems. when you select a different folder (contacts, calendar, journal, tasks) the control is duplicated in the menu bar. it is not calling the addmenubar sub i created. it just creates another control!
anyhow, i need the menu to disappear when a user is in a folder which contains non mailitems.
so i wrtoe the code below, which should loop through and remove any controls on the menu bar with the name 'Jamies control', if the current folders default items arent mailtype. but, when the code runs, it crashes outlook, with a memory problem. this happens everytime, and it happens when the objcontrol.delete method is run
any help would be greatly appreciated, and please, if there is a better way to do this then please let me know
cheers in advance
jamie
Private Sub objexplorer_ViewSwitch()
Dim folder As MAPIFolder
Set folder = Application.ActiveExplorer.CurrentFolder
Dim objCB As Office.CommandBarControls
Dim objControl As Office.CommandBarControl
Set objCB = Application.ActiveExplorer.CommandBars.item("menu bar").controls
If folder.DefaultItemType = olMailItem Then
'remove any controls with the name Jamies Control
For Each objControl In objCB
If objControl.Caption = "&Jamies Control" Then
objControl.Delete
End If
Next
'then we add the new pop up control
addMenuBarControls
Else
For Each objControl In objCB
If objControl.Caption = "&Jamies Control" Then
objControl.Delete
End If
Next
'addMenuBarControls
End If
End Sub