Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Two problems with VB code and custom Menu Bars

Status
Not open for further replies.

Sorwen

Technical User
Nov 30, 2002
1,641
US
I got my supervisor to agree to custom tool bars for this project. Because of the project I have to make the tool bars at runtime. I have two problems the first is I can't get the "Filter For" button to add at runtime. I get the error "Run-time error '5': Invalid procedure call or argument" when it tries to add it. The other buttons add fine if I take it out.

The second error is the custom shortcutbar I create at run time will not show of the form when I right click. Again I have to do it at run time. If I pre-code the form to use the shortcut menu it will work fine, but it will not set at runtime.


Code for adding a new CommandBarButton (The error occurs on the Set newButton. The ID for "Filter For" is 2863. I've tried no item type and msoControlEdit)
Code:
Function CreateMenuItem(MenuName As String, ItemId As Variant, Optional ItemType As Variant)
        
    Dim customBar As CommandBar
    Dim newButton As CommandBarButton
    Set customBar = CommandBars.Item(MenuName)
    Set newButton = customBar.Controls _
                .Add(ItemType, ItemId, , , True)

End Function

Code to create a custom MenuBar and Code to set the menu to be a shortcutmenu
Code:
Function CreateMenu(MenuName As String, Optional Position As Variant, Optional MenuBar As Boolean)
    Dim customBar As CommandBar
    Dim newButton As CommandBarButton
    Set customBar = CommandBars.Add(MenuName, Position, MenuBar, True)
    
    If Position <> msoBarPopup Then
        customBar.Visible = True
    End If
End Function
Code:
Function ConnectRightMenu(MenuBar As String)

    Form_thisform_frm.ShortcutMenuBar = MenuBar

End Function

Thanks for any help you can give.
 
If you've really typed this way
Code:
Set newButton = customBar.Controls _
                .Add(ItemType, ItemId, , , True)

then you've inserted an extra space. Removing the continuation it becomes
Code:
Set newButton = customBar.Controls[COLOR=red red] [/color].Add(ItemType, ItemId, , , True)

and that space shouldn't be there.
 
Thanks, but that has no effect on any of it. It ignores the space. It has no problem creating all of the other buttons just that one. I did try it on the off chance, but no effect. Thanks though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top