편집

다음을 통해 공유


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 MenuBar argument list, as shown in the Macro window in previous versions of Microsoft Access (count down the list, starting from 0).
MenuName Required Variant Use one of the following intrinsic constants:
  • acFile

  • acEditMenu

  • acRecordsMenu

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

Command Required Variant Use one of the following intrinsic constants:
  • acNew

  • acSaveForm

  • acSaveFormAs

  • acSaveRecord

  • acUndo

  • acCut

  • acCopy

  • acPaste

  • acDelete

  • acSelectRecord

  • acSelectAllRecords

  • acObjectRefresh

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

Subcommand Optional Variant 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 Access (count down the list, starting from 0).

Version Optional Variant Use the intrinsic constant acMenuVer70 for code written for Access 95 databases, the intrinsic constant acMenuVer20 for code written for Access version 2.0 databases, and the intrinsic constant acMenuVer1X for code written for 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 Access version 1.x databases will run unchanged. If you are writing code for a Access 95 or version 2.0 database and want to use the 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 MenuBar, MenuName, 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 Access 95 lists if the Version argument is acMenuVer70, the Access version 2.0 lists if the Version argument is Version, and the Access version 1.x lists if Version is acMenuVer1X (or blank).

NOTE: There is no acMenuVer80 setting for this argument. You can't use the DoMenuItem method to display Access 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 Access only for compatibility with previous versions. When you run existing Visual Basic code containing a DoMenuItem method, Access will display the appropriate menu or toolbar command for 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 Access.

Some commands from previous versions of Access aren't available in Access, 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 MenuName, 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.

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.