Get all the videos in this Access VBA collection 100% FREE by signing up at

In this video I talk about the “With” Statement, and 2 DoCmd methods, DoCmd.OpenForm and DoCmd.OpenReport

There are many arguments for the OpenForm and OpenReport methods I will elaborate on at the blog,

This is part 3 of a 3 part video series.

Private Sub Form_Load()
    With Me.ReorderLevel
      .Enabled = True
      .Locked = True
    End With
End Sub


Private Sub Form_Load()
	Me.ReorderLevel.Enabled = True
	Me.ReorderLevel.Locked = True
End Sub

Using the DoCmd Object:

[sourcecode language="vb"]
Option Compare Database

Private Sub btnOpenForm_Click()
    DoCmd.OpenForm "Orders"
End Sub

Private Sub btnOpenReport_Click()
    'open the "Sales by Category" report in preview mode
    DoCmd.OpenReport "Sales by Category", acViewPreview
End Sub

acViewPreview is a constant from the Access object library. I set the reports to open in this mode instead of just sending the report directly to the printer. This way you have a change to review the report before sending it to the printer to print.

To use the OpenForm method, use the following syntax:

DoCmd.OpenForm formname[, view][, filtername][, wherecondition][, datamode][, windowmode][, openargs]

The following table lists the arguments of the OpenForm Method.

Argument Description
formname the name of the form to open.
view The view inwhich a form opens. It can be one of the following constant: acDesign, acFormDS, acNormal (default), and acPreview. By default, the form opens in Form view.

*Interesting Note: Access constants have a two-letter prefix which identifies the object library where it’s defined. Constants from the Access library are prefixed with “ac”, and constants from the VBA Library are prefixed with “vb”

For example:

  • acForm
  • vbCurrency
filtername The name of a query to use to restrict the records being returned.
wherecondition A SQL WHERE clause, without the word WHERE, to use to restrict the records being returned.
datamode The data mode in which a form opens. It can be one of the following constants: acFormAdd, acFormEdit, acFormPropertySettings (default), and acFormReadOnly
windowmode The way in which a window opens. It can be one of the following constants: acDialog, acHidden, acIcon, and acWindowNormal (default). (Take a look at my video post MS Access VBA Control Events – PT3 for a sample of the acDialog option
openargs The expression is used to set the form’s OpenArgs property, This setting is very versatile and is normally used by the receiving form’s Form_OnOpen Event procedure. Take a look at the previous point’s link for an example of it’s use.


Offsite Related Information:

“Go Fund Me” Page

($5 suggested amount)

(…10% of your gift amount will go to charity)

Free! Subscribe To Our YouTube Channel!

Free MS Access VBA Programming Course

Facebooktwitterredditpinterestlinkedinmailby feather
Tags: , , , , ,