Can anyone help, i have written a "few" functions to allow me to create menus but when i try to add a button to a sub menu i get this error:
any ideas, this has got me really stumped.
thanks
Function to create main menu bar
function to create menu popup items
function to create buttons on popup menus
creating the menu
Run time error 5
invalid proceadure or call
any ideas, this has got me really stumped.
thanks
Function to create main menu bar
Code:
Public Function CreateMenu(MenuName As String)
Dim menubar As CommandBar
If fIsCreated(MenuName) Then
Application.CommandBars(MenuName).Delete
End If
Set menubar = Application.CommandBars.Add(MenuName, msoBarTop, True, False)
Application.CommandBars(MenuName).Visible = True
End Function
function to create menu popup items
Code:
Public Function AddMenuMainItem(MenuName As String, ItemType As String, ItemCaption As String, Optional OnAction As String)
Dim menubar As CommandBar
Dim MenuItem As CommandBarControl
Set menubar = Application.CommandBars.ActiveMenuBar
Set MenuItem = menubar.Controls.Add(msoControlPopup)
MenuItem.Caption = ItemCaption
End Function
function to create buttons on popup menus
Code:
Public Function AddMenuSubItem(MenuName As String, MainItemName As String, ItemType As String, ItemCaption As String, ItemIcon As Long, Optional OnAction As String)
Dim menubar As CommandBar
Dim MenuItem As CommandBarButton
Dim SubMenuItem As CommandBarPopup
Dim mycontrol As CommandBarControl
Select Case ItemType
Case "msoControlButton"
Set menubar = Application.CommandBars(MenuName)
Set mycontroll = menubar.Controls(MainItemName)
Set MenuItem = mycontroll.Controls.Add(msoControlButton)
MenuItem.Caption = ItemCaption
MenuItem.OnAction = OnAction
MenuItem.Style = msoButtonAutomatic
MenuItem.FaceId = ItemIcon
Case "msoControlPopup"
Set menubar = Application.CommandBars(MenuName)
Set mycontroll = menubar.Controls(MainItemName)
Set SubMenuItem = mycontroll.Controls.Add(msoControlPopup)
SubMenuItem.Caption = ItemCaption
End Select
End Function
creating the menu
Code:
Call CreateMenu("Main Menu1")
Call AddMenuMainItem("Main Menu1", "msoControlPopup", "&File")
Call AddMenuSubItem("Main Menu1", "&File", "msoControlButton", "&Print Screen", 4, "=docmd.printout")
Call AddMenuSubItem("Main Menu1", "&File", "msoControlButton", "&Edit", 463, "=docmd.quit")
Call AddMenuMainItem("Main Menu1", "msoControlPopup", "&popup2")
Call AddMenuSubItem("Main Menu1", "&popup2", "msoControlPopup", "&Batchs", 0)
Call AddMenuSubItem("Main Menu1", "&Batchs", "msoControlButton", "cap", 0, "=docmd.openform('frmcap')")