Description
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.
Note The DoCmd object replaces the DoCmd statement from versions 1.x and 2.0 of Microsoft Access. The actions that were used as arguments for the DoCmd statement are now methods of the DoCmd object. For example, in Microsoft Access 2.0, you could have used the code DoCmd OpenForm "Orders" to open a form from Access Basic. In Microsoft Access 97, you would use the following syntax: DoCmd.OpenForm "Orders" 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:
See Also ApplyFilter action, Beep action, CancelEvent action, Close action, CopyObject action, DeleteObject action, DoMenuItem action, Echo action, FindNext action, FindRecord action, GoToControl action, GoToPage action, GoToRecord action, Hourglass action, Maximize action, Minimize action, MoveSize action, OpenForm action, OpenModule action, OpenQuery action, OpenReport action, OpenTable action, OutputTo action, PrintOut action, Quit action, Rename action, RepaintObject action, Requery action, Restore action, RunCommand action, RunMacro action, RunSQL action, Save action, SelectObject action, SendObject action, SetMenuItem action, SetWarnings action, ShowAllRecords action, ShowToolbar action, TransferDatabase action, TransferSpreadsheet action, TransferText action.
Example The following example opens a form in Form view and moves to a new record.Sub ShowNewRecord()
DoCmd.OpenForm "Employees", acNormal
DoCmd.GoToRecord , , acNewRec
End Sub