Home  Fees/Services  Access 2010 Template  Tutorials  Access Download  Articles  Search  Contact  Privacy  Links
Macro Programming Examples
Open Report DoCmd
Docmd Macro VBA Example
 





DoCmd Home


DoCmd OpenReport Syntax, Options & Examples

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")

output:
On Error GoTo no_data
Select Case Me.Select_Report
    Case 1
        DoCmd.OpenReport "R_Dispatch_Report", acViewPreview, , crit
    Case 2
        DoCmd.OpenReport "R_Dispatch_Pilot_Report", acViewPreview, , crit
    Case 3
        DoCmd.OpenReport "R_Dispatch_Aircraft_Report", acViewPreview, crit
    Case 4
        DoCmd.OpenReport "R_EDT_Change_Report", acViewPreview, , crit
End Select

Exit Sub
local_err:
rst.Close
' no reservations found
no_data:
Resume exit_ok
exit_ok:

End Sub

More Open Report examples:

Docmd.Openreport in CreateQueryDef in VBA

Docmd.Openreport with Select Case in Access






A Blue Claw Database Design Template:

Prescription Assistance Plan Admin Template
 








A Blue Claw Database Design Article:

Why Choose Microsoft Access
 




Contact Information

Copyright 2000-2014 Blue Claw Database Design