DoCmd.DoMenuItem Method (Access)

Displays the appropriate menu or toolbar command for Microsoft Access.

Syntax

expression .DoMenuItem(MenuBar, MenuName, Command, Subcommand, Version)

expression A variable that represents a DoCmd object.

Parameters

Name

Required/Optional

Data Type

Description

MenuBar

Required

Variant

Use the intrinsic constant acFormBar for the menu bar in Form view. For other views, use the number of the view in the menu bar argument list, as shown in the Macro window in previous versions of Microsoft Access (count down the list, starting from 0).

MenuName

Required

Variant

You can use one of the following intrinsic constants.

  • acFile

  • acEditMenu

  • acRecordsMenu

  • You can use acRecordsMenu only for the Form view menu bar in Microsoft Access version 2.0 and Microsoft Access 95 databases. For other menus, use the number of the menu in the menu name argument list, as shown in the Macro window in previous versions of Microsoft Access (count down the list, starting from 0).

Command

Required

Variant

You can use one of the following intrinsic constants.

  • acNew

  • acSaveForm

  • acSaveFormAs

  • acSaveRecord

  • acUndo

  • acCut

  • acCopy

  • acPaste

  • acDelete

  • acSelectRecord

  • acSelectAllRecords

  • acObjacRefreshect

  • For other commands, use the number of the command in the command argument list, as shown in the Macro window in previous versions of Microsoft Access (count down the list, starting from 0).

Subcommand

Optional

Variant

You can use one of the following intrinsic constants.

  • acObjectVerb

  • acObjectUpdate

  • The acObjectVerb constant represents the first command on the submenu of the Object command on the Edit menu. The type of object determines the first command on the submenu. For example, this command is Edit for a Paintbrush object that can be edited.

  • For other commands on submenus, use the number of the subcommand in the subcommand argument list, as shown in the Macro window in previous versions of Microsoft Access (count down the list, starting from 0).

Version

Optional

Variant

Use the intrinsic constant acMenuVer70 for code written for Microsoft Access 95 databases, the intrinsic constant acMenuVer20 for code written for Microsoft Access version 2.0 databases, and the intrinsic constant acMenuVer1X for code written for Microsoft Access version 1.x databases. This argument is available only in Visual Basic.

NoteNote
The default for this argument is acMenuVer1X, so that any code written for Microsoft Access version 1.x databases will run unchanged. If you're writing code for a Microsoft Access 95 or version 2.0 database and want to use the Microsoft Access 95 or version 2.0 menu commands with the DoMenuItem method, you must set this argument to acMenuVer70 or acMenuVer20.

Also, when you are counting down the lists for the Menu Bar, Menu Name, Command, and Subcommand action arguments in the Macro window to get the numbers to use for the arguments in the DoMenuItem method, you must use the Microsoft Access 95 lists if the Version argument is acMenuVer70, the Microsoft Access version 2.0 lists if the Version argument is Version, and the Microsoft Access version 1.x lists if Version is acMenuVer1X (or blank).

NoteNote
There is no acMenuVer80 setting for this argument. You can't use the DoMenuItem method to display Microsoft Access 2010 commands (although existing DoMenuItem methods in Visual Basic code will still work). Use the RunCommand method instead.

Remarks

Note

In Microsoft Access 97 and later, the DoMenuItem method was replaced by the RunCommand method. The DoMenuItem method is included in this version of Microsoft Access only for compatibility with previous versions. When you run existing Visual Basic code containing a DoMenuItem method, Microsoft Access will display the appropriate menu or toolbar command for Microsoft Access 2000. However, unlike the DoMenuItem action in a macro, a DoMenuItem method in Visual Basic code isn't converted to a RunCommand method when you convert a database created in a previous version of Microsoft Access.

Some commands from previous versions of Microsoft Access aren't available in Access 2010, and DoMenuItem methods that run these commands will cause an error when they're executed in Visual Basic. You must edit your Visual Basic code to replace or delete occurrences of such DoMenuItem methods.

The selections in the lists for the menu name, command, and subcommand action arguments in the Macro window depend on what you've selected for the previous arguments. You must use numbers or intrinsic constants that are appropriate for each MenuBar, MenuName, Command, and Subcommand argument.

If you leave the Subcommand argument blank but specify the Version argument, you must include the Subcommand argument's comma. If you leave the Subcommand and Version arguments blank, don't use a comma following the Command argument.

See Also

Concepts

DoCmd Object

DoCmd Object Members