How to Disable Right-Click Shortcut Menus for Specific Users in Access VBA
Question details
The user needs to disable right-click shortcut menus across all open forms for specific user types using 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 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.
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.
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.
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`.
Initiate a For Each loop targeting the built-in Forms collection by typing `For Each frm In Forms`.
Inside the loop, set the shortcut menu property to false: `frm.ShortcutMenu = False`. Then close the loop with `Next frm`.

Disable Shortcut Menus on Form Load
Instead of looping through all forms globally, disable the shortcut menu for each form individually as it opens.
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.

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.




