• Defining a custom Menu with VBA

    • This topic has 2 replies, 2 voices, and was last updated 24 years ago.
    Author
    Topic
    #355105

    Access 97 SR-1
    Greetings

    Some advice would be appreciated to point me on the way.
    I am attempting to code a custom menu, my first such attempt.
    The top Level on menu bar is to be CUSTOM
    I want the next item to be SEARCH

    The code bombs with Error 438, Object doesnt support this property or method
    —————————————————-
    Sub CustomMenu()
    Dim cbr As CommandBar
    Dim cbcCustom As CommandBarControl
    Dim cbcSearch As CommandBarControl

    Set cbr = CommandBars(“menu Bar”)
    Set cbcCustom = cbr.Controls.Add(msoControlButton)
    With cbcCustom
    .Caption = “Custom”
    .Tag = “Test Menu Item”
    .Style = msoButtonCaption
    End With
    Set cbcSearch = cbcCustom.CommandBar.Add(msoControlButton)
    With cbcSearch
    .Caption = “Search”
    .Tag = “search”
    .Style = msoButtonCaption
    End With
    End Sub
    ——————————————-

    CUSTOM sits very nicely on the Menu Bar even though it has bombed defining SEARCH.

    Thanks in anticipation
    G

    Viewing 0 reply threads
    Author
    Replies
    • #523209

      Hi Geof,

      The reason for the error is that you’re creating a Control Button (“Custom”). You should use the msoControlPopup style for “Custom”. (You’ll have to remove the line that sets the style of Custom to msoButtonCaption – because it’s a popup it doesn’t need that line.)

      Hopefully this will get you started in the right direction.
      HTH thumbup

    Viewing 0 reply threads
    Reply To: Defining a custom Menu with VBA

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: