Home  Fees/Services  Access Templates  Tutorials  Access Download  Articles  Search  Contact  Privacy  Links

DoCmd Examples - Access VBA
Open Report DoCmd

Docmd Macro VBA Example

DoCmd AddMenu
DoCmd ApplyFilter
DoCmd CancelEvent
DoCmd Close
DoCmd CopyObject
DoCmd DeleteObject
DoCmd FindRecord
DoCmd FindNext
DoCmd GotoControl
DoCmd HourGlass
DoCmd Min/Max/Restore
DoCmd OpenForm
DoCmd OpenQuery
DoCmd OpenReport
DoCmd OutputTo
DoCmd RunSQL
DoCmd SendObject
DoCmd TransferDatabase
DoCmd TransferText

Create Export Specs


Microsoft Office:
  MS Access 2003
  Access 2007
  Access 2010
  Access 2013

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.

You did not know that nearly 100 cable and satellite tv installers use our software to manage their device inventory. They never lose track of an expensive device.

Did you know that most template databases often do not do exactly what you need done? We can create a custom template that fits your needs exactly.

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
    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
' no reservations found
Resume exit_ok

End Sub

More Open Report examples:

Docmd.Openreport in CreateQueryDef in VBA

Docmd.Openreport with Select Case in Access

Microsoft Office:
MS Access 2003
Access 2007
Access 2010
Access 2013

A Blue Claw Software Design Template:

Corporate Document Control Solution

A Blue Claw Database Design Article:

Why Choose Microsoft Access

Blue Claw Database Design Downloadable Tutorial:
How To Program Continuous-Continuous Master/Detail Forms  

Contact Information

Copyright 2000-2017 Blue Claw Database Design