Export (0) Print
Expand All
3 out of 8 rated this helpful - Rate this topic

DoCmd Object (Access)

Published: July 16, 2012

You can use the methods of the DoCmd object to run Microsoft Office 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.

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 MsgBox function.

  • RunApp. Use the Shell function to run another application.

  • RunCode. Run the function directly in Visual Basic.

  • SendKeys. Use the SendKeys statement.

  • SetValue. Set the value directly in Visual Basic.

  • StopAllMacros.

  • StopMacro.

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
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.