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 to create a custom MenuBar and Code to set the menu to be a shortcutmenu
Thanks for any help you can give.
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.