Dear friends,
I am using MS Access 2022 (office 365), I am having trouble with creating shortcut menu command for report. I tried to follow the same thing posted by Beacon (How to create a custom shortcut menu command that identifies the calling form/report?), I used MS Office 16.0 object library as reference. The code causes no error, but when on use right mouse click on the form/report that call the sub creating the custom short cut menu, it shows only the standard shortcut menu of ms access. The code posed as said above is here below. Please help to advise.
I am using MS Access 2022 (office 365), I am having trouble with creating shortcut menu command for report. I tried to follow the same thing posted by Beacon (How to create a custom shortcut menu command that identifies the calling form/report?), I used MS Office 16.0 object library as reference. The code causes no error, but when on use right mouse click on the form/report that call the sub creating the custom short cut menu, it shows only the standard shortcut menu of ms access. The code posed as said above is here below. Please help to advise.
Code:
Sub CreateReportShortcutMenu()
Dim cmbReportShortcutMenu 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 cmbReportShortcutMenu = CommandBars.Add("ReportShortcutMenu", msoBarPopup)
With cmbReportShortcutMenu
' Add the Print command.
Set cmbControl = .Controls.Add(msoControlButton, 2521)
' Change the caption displayed for the control.
cmbControl.Caption = "Quick Print"
' Add the One Page command.
Set cmbControl = .Controls.Add(msoControlButton, 5)
' Add the Two Pages command.
Set cmbControl = .Controls.Add(msoControlButton, 639)
' Add the Print command.
Set cmbControl = .Controls.Add(msoControlButton, 15948)
' Change the caption displayed for the control.
cmbControl.Caption = "Select Pages"
' Add the Page Setup... command.
Set cmbControl = .Controls.Add(msoControlButton, 247)
' Change the caption displayed for the control.
cmbControl.Caption = "Page Setup"
' Add the Mail Recipient (as Attachment)... command.
Set cmbControl = .Controls.Add(msoControlButton, 2188)
' Start a new group.
cmbControl.BeginGroup = True
' Change the caption displayed for the control.
cmbControl.Caption = "Email Report as an Attachment"
' Add the PDF or XPS command.
Set cmbControl = .Controls.Add(msoControlButton, 12499)
' Change the caption displayed for the control.
cmbControl.Caption = "Save as PDF/XPS"
' Add the Close command.
Set cmbControl = .Controls.Add(msoControlButton, 923)
' Start a new group.
cmbControl.BeginGroup = True
' Change the caption displayed for the control.
cmbControl.Caption = "Close Report"
'*******************************************************
'* If I was going to use a custom sub/function,
'* this an example of how I would at least start it
'*******************************************************
' Add a blank command
Set cmbControl = .Controls.Add(msoControlButton, 1)
cmbControl.Caption = "Email As PDF"
cmbControl.OnAction = "=MySubFunction()"
End With
Set cmbControl = Nothing
Set cmbReportShortcutMenu = Nothing
End Sub
Sub DeleteContextMenu()
On Error Resume Next
CommandBars("ReportShortcutMenu").Delete
End Sub
Comment