MS ACCESS FORM OBJECTS – PT3

Get all the videos in this Access VBA collection 100% FREE by signing up at https://vbahowto.com/ms-access-tutorial

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, https://vbahowto.com

This is part 3 of a 3 part video series.

'USE THIS:
Private Sub Form_Load()
    With Me.ReorderLevel
      .Enabled = True
      .Locked = True
    End With
End Sub

'INSTEAD OF THIS:

Private Sub Form_Load()
	Me.ReorderLevel.Enabled = True
	Me.ReorderLevel.Locked = True
End Sub
[/sourcecode]

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.

<< MS ACCESS FORM OBJECTS – PT2 | MS ACCESS FORM VALIDATION – PT1 >>




By the way, if you got or are getting value from the VBA information, please give me a tip, thanks!


These posts may help answer your question too...

How to pick a file to load In VBA

Picking a file to load in your Microsoft App is a very important skill to know. In this blog post you will see how to do it. First you need to set a reference to the MS office object library From VBE editor –> select Tools > MS office object library (click check mark) Sub […]

What is the purpose of the Me keyword in Access VBA?

What does the Me keyword mean? “Me” refers to the Access form currently in focus. Instead of writing out the entire form reference, you can just use the keyword “Me” which is easier. Like: Me.txtbox = “I am a textbox on the form that currently has the focus.” or you can update a label’s caption […]

How do I handle errors in Access VBA code?

I am going to give you the answer to “How do I handle errors in Access VBA code?” In my opinion there are 2 ways to handle errors: 1. Avoid the potential for an error to occur. 2. Handle the error in your code. Number 1 – If you have a control on your form […]

How do I run VBA code when form opens

How do I run VBA code when form opens? There are probably several ways people do it, and some may say “He’s not doing it right. It’s done this way…” Good for you. This is the way I do it now, and it has worked well for me. 1. Find the form you want to […]

Previous Post

Access Forms – Access Default Value

Next Post

MS ACCESS FORM OBJECTS – PT2

Leave a Reply

Your email address will not be published. Required fields are marked *