GohDiamond
"Access- Imagineer that!"
- Local time
- Today, 07:26
- Joined
- Nov 1, 2006
- Messages
- 550
I was about to ask a question then I stumbled on this code which I tried. It worked and so I thought I'd share it to save somebody else some pain or to inspire creativity.
Note you MUST have a reference for the Office 12.0 Object Library or Higher (Versions 2007= 12.0, 2010=14.0, 2013= 15.0)
Credit to: http://bytes.com/topic/access/answers/939594-how-create-custom-shortcut-menu-command-identifies-calling-form-report
I hope this helps or inspires someone else who may be looking for a solution like this.
Cheers!
Goh
Sub CreateSimpleShortcutMenu()
Dim cmbShortcutMenu As Office.CommandBar
Dim cmbControl As Office.CommandBarControl
'On Error Resume Next
'Delete the command bar if it already exists
DeleteContextMenu
' Create the shortcut menu.
Set cmbShortcutMenu = CommandBars.Add("SimpleShortcutMenu", msoBarPopup)
With cmbShortcutMenu
'*******************************************************
'* If I was going to use a custom sub/function,
'* this is an example of how I would at least start it
'*******************************************************
' Add a blank command (= with no icon, just text)
Set cmbControl = .Controls.Add(msoControlButton, 1)
cmbControl.Caption = "COMMAND ONE"
cmbControl.OnAction = "=MyFunctionOne()"
' Add a blank command (= with no icon, just text)
Set cmbControl = .Controls.Add(msoControlButton, 1)
cmbControl.Caption = "COMMAND TWO"
cmbControl.OnAction = "=MyDFunctionTwo()"
End With
Set cmbControl = Nothing
Set cmbShortcutMenu = Nothing
End Sub
______________________________________________
Sub DeleteContextMenu()
On Error Resume Next
CommandBars("SimpleShortcutMenu").Delete
End Sub
Dim cmbShortcutMenu As Office.CommandBar
Dim cmbControl As Office.CommandBarControl
'On Error Resume Next
'Delete the command bar if it already exists
DeleteContextMenu
' Create the shortcut menu.
Set cmbShortcutMenu = CommandBars.Add("SimpleShortcutMenu", msoBarPopup)
With cmbShortcutMenu
'*******************************************************
'* If I was going to use a custom sub/function,
'* this is an example of how I would at least start it
'*******************************************************
' Add a blank command (= with no icon, just text)
Set cmbControl = .Controls.Add(msoControlButton, 1)
cmbControl.Caption = "COMMAND ONE"
cmbControl.OnAction = "=MyFunctionOne()"
' Add a blank command (= with no icon, just text)
Set cmbControl = .Controls.Add(msoControlButton, 1)
cmbControl.Caption = "COMMAND TWO"
cmbControl.OnAction = "=MyDFunctionTwo()"
End With
Set cmbControl = Nothing
Set cmbShortcutMenu = Nothing
End Sub
______________________________________________
Sub DeleteContextMenu()
On Error Resume Next
CommandBars("SimpleShortcutMenu").Delete
End Sub
Note you MUST have a reference for the Office 12.0 Object Library or Higher (Versions 2007= 12.0, 2010=14.0, 2013= 15.0)
Credit to: http://bytes.com/topic/access/answers/939594-how-create-custom-shortcut-menu-command-identifies-calling-form-report
I hope this helps or inspires someone else who may be looking for a solution like this.
Cheers!
Goh
Last edited: