DoCmd Object

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

                                   


You can use the methods of the DoCmd object to run Microsoft Access actions from Visual Basic. An action performs tasks such as closing windows, opening forms, and setting the value of controls. For example, you can use the OpenForm method of the DoCmd object to open a form, or use the Hourglass method to change the mouse pointer to an hourglass icon.

Syntax

[application.]DoCmd.method [arg1, arg2, ...]

The DoCmd object has the following arguments.

Argument Description
application Optional. The Application object.
method One of the methods supported by this object.
arg1, arg2, ... The arguments for the selected method. These arguments are the same as the action arguments for the corresponding action.

Remarks

Most of the methods of the DoCmd object have arguments  some are required, while others are optional. If you omit optional arguments, the arguments assume the default values for the particular method. For example, the OpenForm method uses seven arguments, but only the first argument, formname, is required. The following example shows how you can open the Employees form in the current database. Only employees with the title Sales Representative are included.

DoCmd.OpenForm "Employees", , ,"[Title] = 'Sales Representative'"

The DoCmd object doesn't support methods corresponding to the following actions:

  • AddMenu.

  • MsgBox. Use the function.

  • RunApp. Use the function to run another application.

  • RunCode. Run the function directly in Visual Basic.

  • SendKeys. Use the statement.

  • SetValue. Set the value directly in Visual Basic.

  • StopAllMacros.

  • StopMacro.

For more information on the Microsoft Access action corresponding to a DoCmd method, search the Help index for the name of the action.