Appendix: The DoCmd Object


Overview

One of the more interesting objects in the Access object model is DoCmd. DoCmd originally appeared in Versions 1.0 and 2.0 of Access Basic, before a standardized version of Visual Basic for Applications became the programming language of Access. With the incorporation of VBA into Access, DoCmd then changed from a language component to a portion of the object model. In any case, it remains one of the more unique features of Access, notable for the diversity of its functionality. This appendix documents the methods supported by the DoCmd object.

The methods of the DoCmd object also correspond more or less directly to “macro actions” that are available in the Action column of the Macro dialog box. However, a few macro actions (MsgBox, RunApp, RunCode, SendKeys, SetValue, StopAllMacros, and StopMacro) were not implemented as members of the DoCmd object, since they are readily available as parts of VBA itself.

In Access, the DoCmd object is returned by the DoCmd property of the Application object. Since Application is a global object (that is, its members can be called from code without requiring that a reference to an Application object be instantiated), the methods of the DoCmd object can be called as follows:

DoCmd.<method_name>

In the syntax statements, parameter names are indicated in italics. For example, in the statement

DoCmd.SetWarnings WarningsOn 

WarningsOn is the method’s single parameter. This is the name that you use if you are using named arguments in calling a method. For example:

DoCmd.SetWarnings WarningsOn:=True

If you are using positional arguments, you replace the parameter placeholder with the value you want to pass to the method.. For example:

DoCmd.SetWarnings False

Many of the method calls have optional arguments, which are indicated by brackets in the syntax statements in this appendix. In general, these can be omitted, except that if you are using positional arguments, commas serving as placeholders must be present to indicate omitted optional values that precede an optional value that is provided. If you are using named arguments, all optional arguments can simply be omitted.




Access VBA Programming
Microsoft Access VBA Programming for the Absolute Beginner
ISBN: 1598633937
EAN: 2147483647
Year: 2006
Pages: 214
Authors: Michael Vine

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net