DoMenuItem Method

Applies To

DoCmd Object.

Description

The DoMenuItem method carries out the DoMenuItem action in Visual Basic. For more information on how the action and its arguments work, see the action topic.

Syntax

DoCmd.DoMenuItem menubar, menuname, command [, subcommand] [, version]

The DoMenuItem method uses the following arguments.

Argument Description
menubar Use the intrinsic constant acFormBar for the menu bar in Form view.

For other views, switch to the Macro window, and use the number of the view in the Menu Bar argument list (count down the list, starting from 0).

menuname 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 for Windows 95 databases.

For other menus, switch to the Macro window, and use the number of the menu in the Menu Name argument list (count down the list, starting from 0).


Argument Description
command You can use one of the following intrinsic constants:

acNew
acSaveForm
acSaveFormAs
acSaveRecord
acUndo
acCut
acCopy
acPaste
acDelete
acSelectRecord
acSelectAllRecords
acObject
acRefresh

For other commands, switch to the Macro window, and use the number of the command in the Command argument list (count down the list, starting from 0).

subcommand 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, switch to the Macro window, and use the number of the subcommand in the Subcommand argument list (count down the list, starting from 0).

version 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.


Note 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 acMenuVer20, and the Microsoft Access version 1.x lists if version is acMenuVer1X (or blank).

Remarks

The selections in the lists for the Menu Name, Command, and Subcommand action arguments in the Macro window depend on what you have 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

AddMenu Action, DoCmd Object, DoMenuItem Action, SendKeys Statement.

Example

This example uses the DoMenuItem method to carry out the Paste command on the Edit menu in Form view in a Microsoft Access for Windows 95 database.


DoCmd.DoMenuItem acFormBar, acEditMenu, acPaste, , acMenuVer70

The next example carries out the Tile command on the Window menu in Form view in a Microsoft Access version 2.0 database.


DoCmd.DoMenuItem acFormBar, 4, 0, , acMenuVer20