Microsoft KB Archive/210248

= ACC2000: How to Open Multiple Instances of a Form =

Article ID: 210248

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q210248



Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).



SUMMARY
This article shows you how to use Visual Basic for Applications to open multiple instances of a form. Being able to open multiple instances of a form enables you to work on more than one record at once. For example, in an Order Entry application, you can start taking an order, pause and take a second order, and then return to the first order, without losing any data.

NOTE: This article explains a technique demonstrated in the sample file, FrmSmp00.mdb. For information about how to obtain this sample file, please see the following article in the Microsoft Knowledge Base:

233324 ACC2000: Microsoft Access Sample Forms Database Available in Download Center

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.



MORE INFORMATION
The syntax for opening multiple instances of a form includes a Set statement, the keyword New, and a form reference, as in the following example: Set x = New Form_Form1 Because you can't use the New keyword to create a new instance of a lightweight object, any form that you intend to use the New keyword with must have its HasModule property set to True.

When you open multiple instances of a form, the original instance is the only form object that is stored permanently in the database. The other instances are temporary and are removed from memory when you close them.

NOTE: When you close the original instance of a form, all other instances of the form are closed as well.

To open multiple instances of a form, follow these steps.

CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

 Open the sample database Northwind.mdb. Open the Customers form in Design view. On the View menu, click Code to open the editor.  Type the following line in the Declarations section: Option Compare Database Option Explicit Dim frmX as Form  Close the editor or press ALT-F11 to switch back to Access.  Add a command button to the Customers form and set the following properties: <pre class="fixed_text">  Command Button: --  Name: cmdOpenNewCust Caption: Open Customers OnClick: [Event Procedure] </li>  Set the OnClick property of the command button to the following event procedure: Private Sub cmdOpenNewCust_Click Set frmX = New Form_Customers frmX.setfocus End Sub </li> Save and close the Customers form.</li> View the Customers form in Form view and click the command button, Open Customers.

Note that a second instance of the Customers form opens.</li></ol>

<div class="references_section">