|[ Team LiB ]|
Recipe 9.2 Create a Form with No Menu or Toolbar
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:
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.
|[ Team LiB ]|