Applies To Application object, DoCmd object.
Description
The RunCommand method runs a built-in menu or toolbar command.
Syntax [object.]RunCommand command The RunCommand method has the following arguments.Argument | Description |
object | Optional. The Application object or the DoCmd object. |
command | An intrinsic constant that specifies which built-in menu or toolbar command is to be run. |
Remarks Each menu and toolbar command in Microsoft Access has an associated constant that you can use with the RunCommand method to run that command from Visual Basic.
For a list of possible constants for the command argument, see RunCommand Method Constants. You can also view these constants in the Object Browser. Select Access in the Project/Library box, then select AcCommand in the Classes list. The constants appear in the Members Of list. You can't use the RunCommand method to run a command on a custom menu or toolbar. You can only use it with built-in menus and toolbars. The RunCommand method replaces the DoMenuItem method of the DoCmd object.See Also RunCommand action.
Example The following example uses the RunCommand method to open the Options dialog box (available by clicking Options on the Tools menu):Function OpenOptionsDialog() As Boolean
On Error GoTo Error_OpenOptionsDialog
DoCmd.RunCommand acCmdOptions
OpenOptionsDialog = True
Exit_OpenOptionsDialog:
Exit Function
Error_OpenOptionsDialog:
MsgBox Err & ": " & Err.Description
OpenOptionsDialog = False
Resume Exit_OpenOptionsDialog
End Function