Microsoft Office Tutorials and References
In Depth Information
Opening Forms with DoCmd
Macros and the DoCmd object
Access macros (see Book VI) use the DoCmd
object to carry out most of their actions. Often,
you can use macros to write a series of DoCmd
statements without the complexities of typing
each statement manually. Create a macro to
do whatever you want your code to do; then
convert the macro to VBA code, as we discuss
in Chapter 1 of this minibook. When you open
the converted macro in Visual Basic Editor, you
see that most, if not all, of its actions are
converted to DoCmd statements. Then you can cut
and paste those statements into some other
procedure that you’re writing or just add any
necessary code to the converted macro.
Because no optional arguments are specified, no filter is applied, and all
other optional settings take on their default values. Opening the form by
double-clicking its name in the Navigation Pane accomplishes the same thing.
The following statement opens a form named Products Form, displaying
only those records in which the Selling Price field contains a number
greater than 100:
DoCmd.OpenForm “Products Form”, , , “[Selling Price] > 100”
The following statement opens a form named Sales Tax Calcs with the
Window Mode property set to the dialog-box style:
DoCmd.OpenForm “Sales Tax Calcs”, , , , , acDialog
As you can see, the DoCmd object offers a lot of flexibility in specifying how
you want to open a form. The same is true of many other methods of the
DoCmd object. These few examples don’t even come close to showing all the
variations. The important things are knowing that the DoCmd object exists and
that you can perform many Access actions on objects within your database.
Chapter 4
Closing a form with DoCmd
Just as you can open a form with DoCmd, you can use DoCmd to close it. The
syntax for closing an object with DoCmd is
DoCmd.Close( ObjectType , ObjectName , Save )
Each argument in the syntax represents the following:
ObjectType : The type of object that you want to close expressed with
one of the available constants, such as acForm, acReport, acTable,
and acQuery
ObjectName : A string expression that identifies an object currently open
Search JabSto ::

Custom Search