You'd like to completely disable menus for a form, and the toolbar too. Is there any way to remove menus and toolbars from a form?
If you set the MenuBar property of a form to point to a macro in Access that contains no macro actions, you can trick Access into not displaying any menus. This solution demonstrates this trick and also discusses how you can apply it to the global menus of an application. In addition, you'll learn how to use VBA code to remove a form's toolbar.
To create forms in your database without any menus, follow these steps:
Create a new macro sheet without any actions. The mcrNoMenus macro sheet in 09-02.MDB has no macro actions.
Create a new form or open an existing form in design view. Select the menu macro from Step 1 as the MenuBar property for the form.
Add the following Activate and Deactivate event procedures to the form to remove the toolbar for this form only:
Private Sub Form_Activate( ) DoCmd.ShowToolbar "Form View", acToolbarNo End Sub Private Sub Form_Deactivate( ) DoCmd.ShowToolbar "Form View", acToolbarWhereApprop End Sub
Optionally, you may wish to also eliminate right-click shortcut menus for your form. To do this, set the ShortcutMenuBar property of the form to No.
Save the form.
To see an example, load the 09-02.MDB sample database. Open the frmCustomerDefaultMenus form in form view and note that the default Access menu and toolbar are available at the top of the screen (see Figure 9-4). Close this form and open frmCustomerNoMenus. Note the absence of any menu or toolbar for the form (see Figure 9-5).
In early versions of Access, macros were the only method of creating custom menus. Despite the newer Command Bar menus and toolbars supported in recent versions of Access, you can still create custom menus in Access by creating menu macros. When you open a form with custom menus, Access reconstructs the custom menus from the hierarchy of macros attached to the form's MenuBar property. However, if you attach an empty macro to the MenuBar property, Access creates a blank menu for the form.
The ShowToolbar macro action, which you call in VBA using DoCmd.ShowToolbar, enables you to show or hide any toolbar. The code hides the default toolbar when the form becomes active. The Deactivate code is equally important?without it, that toolbar will remain hidden for all subsequent forms that you view. The Deactivate event procedure tells Access to show that toolbar again whenever it is appropriate.
You may want to eliminate menus for a form to reduce the complexity of your application or to remove potential chinks in your application's armor. Whenever you remove built-in functionality from forms, however, you must ensure that users of your forms can still perform essential activities. For example, you wouldn't want to remove menus and set the ControlBox and CloseButton properties of your form to No unless you have added either a toolbar button or a command button that could be used to close the form. Another alternative is to use the View Toolbars Customize dialog to create your own menus and toolbars containing only the commands you want to expose.
In addition to removing menus
for a single form, you can set the application's
default menu bar to point to an empty macro. Select Tools
Startup to set the default menu bar. In Figure 9-6,
we set the default MenuBar property of the Startup dialog to
mcrNoMenus, thus removing menus for all forms in the application for
which custom menus were not created. Another option is to uncheck the
AllowFullMenus property, which tells Access to remove all menu
commands that allow users to switch to design view.
You can also customize the default shortcut menus using the Startup dialog by changing the AllowDefaultShortcutMenus and ShortcutMenuBar properties.