PDA

Click to See Complete Forum and Search --> : checking if a control exists - please help


jamielawjen
Jan 27th, 2006, 07:41 AM
hi there

i need to check first that a control exists before adding new one,

how do i do this

i have the following code, but im not sure how to check if the control object is filled or not



Dim testcontrol As Office.CommandBarControl
Set testcontrol = objApp.ActiveExplorer.CommandBars.item("Menu Bar").controls.item("My Control")

If testcontrol = false Then
'add control
else
'control exists
end if




alternatively, is there some way chekc if a control exists like

objApp.ActiveExplorer.CommandBars.item("Menu Bar").controls.exists("my control")

i am using vb6, outlook 2000+
many thanks

Jamie

mikeyc1204
Jan 27th, 2006, 08:26 AM
Most if not all examples I've seen of commandbar manipulation involve deleting the old control and adding the new one instead of figuring a way to check for it's existance.
Sub RemoveControl()
On Error Resume Next
objApp.ActiveExplorer.CommandBars.item("Menu Bar").controls.item("My Control").Delete
End Sub

Sub AddControl()
Call RemoveControl
objApp.ActiveExplorer.CommandBars.item("Menu Bar").Controls.Add(....)
End Sub