DoCmd OpenReport in Microsoft Access
You can use the Open Report action to open a report in Design view or Print Preview, or to print the report immediately in screen view (normal view). You can also restrict the records that are printed in the report using a criteria option. The example (below) shows the Docmd.openreport method when used to restrict the selection of records.
Here are the syntax and options for the open report command:
expr.OpenReport(ReportName, View, FilterName, WhereCondition, WindowMode, OpenArgs)
expr is a required expression in this case DoCmd.
ReportName is a required string variable. A variant string expression which is the name of a report in your database. If you run VBA code containing the OpenReport method in a library database, MS Access looks for the report with this name first in the library database and secondly in the current database.
View Optional AcView is the mode in which the report opens. Acview can be anyone of the following constants:
acViewDesign – shows the report in design mode ready for modification
acViewNormal (default) Send the report to the current default printer queue
acViewPreview – shows the report on the screen
FilterName is optional. A string expression that is a name of a query in the database.
WhereCondition optional string expression that’s a valid SQL WHERE clause without the keyword WHERE.
WindowMode Optional AcWindowMode. The mode in which the report opens. The AcWindowMode can be any of these AcWindowMode constants.
acDialog The report’s Modal and PopUp properties are set to Yes.
acHidden The report is hidden.
acIcon The report opens minimized in the Windows taskbar.
acWindowNormal default The report is in the mode set by its current properties settings.
OpenArgs Optionally sets the OpenArgs property.
Below is a VB examples showing the use of the openreport method. The beginning of the code demonstrates the creation of a criteria option statement for the open report method. The specific openreport code lines are bolded towards the bottom of the subroutine:
Private Sub Command5_Click()
Dim crit As String
crit = “Flight_ID” & Choose(get_global(“flight_type”), “>-1”, “=0”, “<>0”)
On Error GoTo no_data
Select Case Me.Select_Report
DoCmd.OpenReport “R_Dispatch_Report”, acViewPreview, , crit
DoCmd.OpenReport “R_Dispatch_Pilot_Report”, acViewPreview, , crit
DoCmd.OpenReport “R_Dispatch_Aircraft_Report”, acViewPreview, crit
DoCmd.OpenReport “R_EDT_Change_Report”, acViewPreview, , crit
‘ no reservations found
More Open Report examples:
Microsoft Access DoCmd Tutorials: