DoCmd.OpenForm

Open a form.

Syntax
      DoCmd.OpenForm(FormName, View, FilterName, WhereCondition,
                     DataMode, WindowMode, OpenArgs)


Key
   FormName       The name of the form to open.

   View           An AcFormView constant that specifies the view
                  in which the form will open. Default=acNormal

   FilterName     The name of a query saved in the current database.

   WhereCondition An SQL WHERE clause (without the word WHERE.)

   DataMode       An AcFormOpenDataMode constant that specifies the
                  data entry mode for the form.
                  applies only to forms opened in Form or Datasheet view.

   WindowMode     An AcWindowMode constant that specifies the
                  window mode in which the form opens.
                  default = acWindowNormal.

   OpenArgs       A string expression that is used to set the form’s
                  OpenArgs property. This can then be used by code
                  in a form module.

Use OpenForm to open a form in Form view, form Design view, Print Preview, or Datasheet view.

Open the same form more than once

To open the same form twice, requires using a form variable/reference, the Set statement creates a temporary copy of the form in memory.

In the declarations section:

Option Explicit
Dim frmX as Form

In the OnClick property of a command button:

Private Sub cmdDemo_Click()    
  Set frmX = New Form_frmDemo
  frmX.setfocus
End Sub 

Examples

'Open frmAppointments and display records for the current patient:
DoCmd.OpenForm "frmAppointments", , , "PatientID=" & Me!txtPatientID

'Open frmTravel and display all the records
DoCmd.OpenForm "frmTravel"

“I get all the news I need from the weather report” ~ Paul Simon

Related:

Q210248 - How to Open Multiple Instances of a Form
OpenReport - Open a report
SetParameter - Set a parameter before opening a Form or Report.


© Copyright SS64.com 1999-2016
Some rights reserved