Access VBA Macro Programming

(Joao Candeias) #1
Action queries (such as delete, insert, or append) can be run in this way, but you can also
use:

CurrentDb.Execute "MyQuery"

OpenReport
TheOpenReportmethod will open a report and is very useful where you have a hierarchy of
reports that the user navigates through. The syntax is:
DoCmd.OpenReport _ (ReportName,View,FilterName,WhereCondition,WindowMode,OpenArgs)

The ReportName is a required parameter, but the others are optional:

 View An acFormView constant that specifies the view that the form will open in.
This is acNormal by default.
 FilterName The name of a query in the current database.
 WhereCondition An SQL WHERE clause without the word WHERE.
 WindowMode An acWindowMode constant that specifies the window that the form
opens in.
 OpenArgs This sets the form’sOpenArgsproperty.

OpenTable
TheOpenTablemethod will open a table so that the user can scroll through the results.
However, it is better to open a form (based on a table) as a datasheet so that the user has all
the filtering functionality. The syntax is:

DoCmd.OpenTable(TableName,View,DataMode)

The TableName is a required parameter, but the others are optional:

 View An acFormView constant that specifies the view that the form will open in.
This is acNormal by default.
 DataMode An acFormOpenDataMode constant that specifies the data entry mode for
the form.

PrintOut
ThePrintOutmethod will print out the active object in the database, which can be a form, a
report, or a datasheet. The syntax is:
DoCmd.PrintOut(PrintRange,PageFrom,PageTo,PrintQuality,Copies,CollateCopies)

216 Microsoft Access 2010 VBA Macro Programming

Free download pdf