Results 1 to 2 of 2

Thread: checking if a control exists - please help

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    80

    checking if a control exists - please help

    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


    VB Code:
    1. Dim testcontrol As Office.CommandBarControl
    2.     Set testcontrol = objApp.ActiveExplorer.CommandBars.item("Menu Bar").controls.item("My Control")
    3.  
    4.     If testcontrol = false Then
    5. 'add control
    6. else
    7. 'control exists
    8. 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
    Last edited by jamielawjen; Jan 27th, 2006 at 08:45 AM.

  2. #2
    Lively Member
    Join Date
    Jun 2005
    Posts
    112

    Re: checking if a control exists - please help

    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.
    VB Code:
    1. Sub RemoveControl()
    2.     On Error Resume Next
    3.     objApp.ActiveExplorer.CommandBars.item("Menu Bar").controls.item("My Control").Delete
    4. End Sub
    5.  
    6. Sub AddControl()
    7.     Call RemoveControl
    8.     objApp.ActiveExplorer.CommandBars.item("Menu Bar").Controls.Add(....)
    9. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width