Run an Access menu or toolbar command.
Syntax expression .RunCommand(Command) Key expression A variable that represents a built-in command.
The RunCommand method runs the specified menu command. If the menu brings up a dialog box, the dialog box appears.
In many cases a DoCmd method will offer better automation with no user input required e.g. RunCommand acCmdPrint vs DoCmd.PrintOut acSelection
Newer versions of Microsoft Access support a larger set of RunCommand constants corresponding to new Access features.
RunCommand replaces the DoCmd.DoMenuItem method from Access 2.0, DoMenuItem is still provided for backwards compatibility only.
To save the current record, the preferred syntax is
If Me.Dirty = True Then Me.Dirty = False
If Me.Dirty Then Me.Dirty = False
Which means "if the record has changes that can be saved, then save them." Setting the me.dirty property will work even if the form does not have focus, so it is slightly more robust than calling the menu command acCmdSaveRecord.
Example function that launches the Tools ➞ Options dialog box:
Function OpenOptionsDialog() As Boolean On Error GoTo Error_OpenOptionsDialog DoCmd.RunCommand Options OpenOptionsDialog = True
Exit_OpenOptionsDialog: Exit Function
Error_OpenOptionsDialog: MsgBox Err & ": " & Err.Description OpenOptionsDialog = False Resume Exit_OpenOptionsDialog End Function
“You learn to speak by speaking, to study by studying, to run by running, to work by working; in just the same way, you learn to love by loving” ~ Anatole France
AccessRunCommands - List of all the Access run commands