logo
search
VBA & Macro Problems

How to Disable Right-Click Shortcut Menus for Specific Users in Access VBA

Rana GarciaRana Garcia Sep 28, 2026 870 views

Question details

The user needs to disable right-click shortcut menus across all open forms for specific user types using VBA.

How to Disable Right-Click Shortcut Menus for Specific Users in Access VBA
Product
Microsoft Access
Device & OS
not provided
Scenario
Securing an Access database by restricting certain user types from accessing form shortcut menus dynamically via VBA.
Observed behavior
Attempts to loop through forms resulted in "Variable not defined" and "Object doesn't support this property or method" errors because invalid VBA constructs like CurrentProject.Forms and Continue For were used.
Before you start

Before running VBA scripts that alter form properties globally, ensure you have a recent backup of your Access database. Verify that your user roles are properly initialized, such as within a TempVars object, to avoid locking yourself out of essential menus.

Solution 1Recommended

Use the Open Forms Collection to Disable Shortcut Menus

Correctly declare your variables and loop through the open Forms collection to disable the shortcut menu for all currently active forms.

In Access VBA, you must use the `Forms` collection to reference open forms. Constructs like `CurrentProject.Forms` do not exist in the Access object model, and `Continue For` is not supported in VBA at all.

Because this method iterates over the `Forms` collection, you do not need to check if a form is loaded (using `IsLoaded`); the collection inherently only contains forms that are currently open.

1
Declare the Form Variable

Open your VBA editor and ensure you properly declare your form variable to prevent "Variable not defined" errors. Type `Dim frm As Form` at the beginning of your procedure.

2
Validate the User Type

Add logic to check the current user's role. For example, use an If statement to verify the user type stored in TempVars: `If TempVars("UserType") = "Restricted" Then`.

3
Loop Through the Forms Collection

Initiate a For Each loop targeting the built-in Forms collection by typing `For Each frm In Forms`.

4
Disable the Shortcut Menu Property

Inside the loop, set the shortcut menu property to false: `frm.ShortcutMenu = False`. Then close the loop with `Next frm`.

Use the Open Forms Collection to Disable Shortcut Menus
Navigation Forms: Keep in mind that the main Access application window and specific Navigation forms might require their own custom configuration to fully restrict right-click capabilities.
Free Microsoft Office alternative

Manage Your Data and Macros with WPS Spreadsheets

While WPS Office does not include a direct equivalent to Microsoft Access databases, it offers WPS Spreadsheets—a powerful, lightweight, and free alternative to Excel that fully supports advanced VBA and Macro scripting for your data management and automation needs.

Free and lightweight alternative to Microsoft OfficeHigh compatibility with Microsoft Excel formats (.xlsx, .xls) and macro-enabled workbooks (.xlsm)Advanced VBA and Macro support to automate your data tasks without rewriting codeFamiliar, intuitive user interface for a seamless migration
microsoft office alternative - wps office

Frequently Asked Questions

Why do I get an error using CurrentProject.Forms in Access VBA?

CurrentProject.Forms is not a valid VBA construct for referencing open forms in Microsoft Access. To interact with open forms, you must use the global `Forms` collection instead.

Can I use the 'Continue For' statement in VBA loops?

No, VBA does not support the 'Continue For' statement commonly found in other programming languages. To skip an iteration in a VBA loop, you should use an `If...Then` block to conditionally execute the code inside the loop.

How do I check if a form is loaded before modifying its properties?

When you loop through the built-in `Forms` collection, checking if a form is loaded via `IsLoaded` is unnecessary. The `Forms` collection only contains forms that are actively open.