Code Samples for Businesses, Schools & Developers

First Published 8 Oct 2024


A fellow Access developer (Jeff N.) contacted me recently to ask how the right click context menu can be disabled in Access reports.

Access forms have a boolean Shortcut Menu property which by default is enabled.

Form Shortcut Menu Property
When the property is set to No (disabled), all right click shortcuts are disabled for that form.
This allows the developer to control what actions can be done by end users whilst the form is open.

However, the property exists only for forms. Reports do not have an equivalent property. This seems to be a strange omission.

If you want to limit user actions from reports, there are a few alternatives:

1.   All shortcuts can be disabled by unticking the Default Shortcut Menus checkbox in Access Options

Access Options
      This can also be done using VBA code - see my article: Improve Security in Access Databases - A Tutorial

      However, this action applies globally. The developer didn’t want to do that.

2.   For an individual report, you can replace the shortcut menus by creating a macro that does nothing and add it to the shortcut menu bar property of the report.

Shortcut Menu Bar Property
a)   Create an empty context menu using a macro mcrBlank:

Blank Macro
     Right clicking now displays the following empty shortcut menu:

Empty Shortcut Menu
      However, this can be confusing to end users – see my article: Strange Dotted Square Bug Annoyance - FIXED

b)   Alternatively, add the menu item 'Shortcut Menu Disabled'. To do so, add the macro mcrNoShortcut in the Shortcut Menu Bar property.

No Shortcut Macro
      Now when the report is right clicked, the following 'context menu' is displayed:

Shortcut Menu Disabled
      This is simple to do and works well. However, showing a shortcut menu stating that they are disabled isn’t ideal.

3.   In my opinion, a more satisfactory solution is to identify and disable all the report command bars used in print preview / report or layout views.

      There are six of these command bars. It took me well over an hour to identify these, partly because none of them has ‘report’ in the command bar name!
      To add insult to injury, the last one (ID=153) is unnamed – the ID value may vary on different machines and whenever Access is restarted

      To manage these command bars, copy the following two procedures into a standard module:

Sub DisableShortcutMenus()

    'disable shortcut menus in all report views (except design)
    CommandBars("Form View Popup").Enabled = False     'report/layout view
    CommandBars("Print Preview Popup").Enabled = False     'print preview
    CommandBars("Form View Control").Enabled = False     'control in report view
    CommandBars("Form View Subform").Enabled = False     'subreport in report view
    CommandBars("Form View Subform Control").Enabled = False     'subreport control in report view
    CommandBars(153).Enabled = False     'title bar in all views (number may change!)

End Sub

'------------------------------------------------

Sub EnableShortcutMenus()

    'enable shortcut menus in all report views (except design)
    CommandBars("Form View Popup").Enabled = True     'report/layout view
    CommandBars("Print Preview Popup").Enabled = True     'print preview
    CommandBars("Form View Control").Enabled = True     'control in report view
    CommandBars("Form View Subform").Enabled = True     'subreport in report view
    CommandBars("Form View Subform Control").Enabled = True     'subreport control in report view
    CommandBars(153).Enabled = True     'title bar in all views (number may change!)

End Sub


      Call the first procedure from the Report_Open event:

Private Sub Report_Open(Cancel As Integer)
    DisableShortcutMenus
End Sub


      VERY IMPORTANT: Reverse this action in the Report_Close event

Private Sub Report_Close()
    EnableShortcutMenus
End Sub



      If you fail to re-enable the shortcut menus, this will affect all forms and reports - both in the current database and all other Access databases.

      NOTE:
      I did find 5 other command bars with ‘report’ in the name – all are used in design view

Report Command Bars


Summary / Action

Whilst there are workarounds to manage shortcut menus in reports, in my opinion, none of these are ideal.

All of this ‘palaver’ could easily be avoided by adding the boolean ShortcutMenu property to reports.
A quick online search for ‘disable shortcut menu in access reports’ shows this is a frequent request on forums etc. Unfortunately, this isn't something that individual developers can do.

I have put in a request to the Access team for this property to be added to reports.
Whilst this is unlikely to be a high priority for the team, I expect it could be done fairly easily for reports.
If you would find the feature useful, please let me know using the Feedback button below



Download

Click to download the example app and code:           Disable Report Shortcut Menu      (ACCDB - zipped)



Feedback

Please use the contact form below to let me know whether you found this article interesting/useful or if you have any questions/comments.

Please also consider making a donation towards the costs of maintaining this website. Thank you



Colin Riddington           Mendip Data Systems                 Last Updated 8 Oct 2024



Return to Code Samples Page




Return to Top