MenuBar Property

Applies To

Application Object, Form, Report.

Description

You can use the MenuBar property to specify the menu bar macro that will to display a custom menu bar for a database, form, or report.

Setting

Enter the name of the menu bar macro that displays a custom menu bar. If you leave the MenuBar property setting blank, Microsoft Access displays the built-in (default) menu bar or the application’s global menu bar.

You can set this property using the object’s property sheet, a macro, or Visual Basic.

In Visual Basic, set this property using a string expression that is the name of the menu bar macro you want to run.

To display the built-in menu bar for a database, form, or report using a macro or Visual Basic, set the property to a zero-length string (" ").

Tip To create a menu bar macro, you can use the Menu Builder by clicking the Build button in the MenuBar property box of the form or report you want to attach the menu to. The Menu Builder creates and names the menu bar macro and the macro group containing the actions for the menu commands on the menus you create. If you use the Menu Builder to create the menu bar macro and the macro group for the menus on this menu bar, you can also use the Menu Builder to edit this macro and macro group.

Remarks

When you use the MenuBar property with forms and reports, Microsoft Access runs the specified menu bar macro and displays the custom menu bar when the form or report is opened. This menu bar is displayed whenever the form or report has the focus.

The menu bar macro contains AddMenu actions that create the drop-down menus on the custom menu bar. For each drop-down menu, the menu bar macro names the macro group that defines the commands on the menu. If you make changes to the menu bar macro or the macro group that defines the commands on the drop-down menus while the form or report is open, you must close the form or report and reopen it to see the changes in the custom menu bar and its menus.

You can’t use any action except AddMenu in a menu bar macro.

When used with the Application object, the MenuBar property enables you to display a custom menu bar throughout the database. However, if you’ve set the MenuBar property for a form or report in the database, the custom menu bar of the form or report takes precedence over the database’s custom menu bar. You can display a different custom menu bar for a specific form or report by setting its MenuBar property to a different menu bar macro. When the form or report has the focus, the custom menu bar for the form or report is displayed; when the form or report loses the focus, the custom menu bar for the database is displayed.

Note You can switch between a database’s custom menu bar and the built-in menu bar by pressing CTRL+F11.

See Also

AddMenu Action, AllowFullMenus Property, Application Object, ShortcutMenuBar Property, StartupMenuBar Property.

Example

The following example sets the MenuBar property to a menu bar macro named CustomerMenu.


Forms![Customers].MenuBar = "CustomerMenu"

To display the built-in menu bar for the form or the application global menu, you set the MenuBar property to a zero-length string (" ").


Forms![Customers].MenuBar = ""