ACC: How to Open Multiple Instances of a Form

Last reviewed: October 24, 1997
Article ID: Q135369
The information in this article applies to:
  • Microsoft Access versions 7.0, 97

SUMMARY

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

This article describes how you can open multiple instances of a form using Visual Basic for Applications. Opening multiple instances of a form gives you the flexibility 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 files, FrmSampl.exe (for Microsoft Access for Windows 95 version 7.0) and FrmSmp97.exe (for Microsoft Access 97). For information about how to obtain these sample files, please see the following articles in the Microsoft Knowledge Base:

   ARTICLE-ID: Q150895
   TITLE     : ACC95: Microsoft Access Sample Forms Available on MSL

   ARTICLE-ID: Q175066
   TITLE     : ACC97: Microsoft Access 97 Sample Forms Available on MSL

MORE INFORMATION

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.

The syntax for opening multiple instances of a form includes a Set statement, the keyword "New" (without the quotation marks), and a form reference, as in the following example:

   Set x = New Form_Form1

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 once 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: Following the steps in this example will modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and perform these steps on a copy of the database.

  1. Open the sample database Northwind.mdb.

  2. Open the Customers form in Design view.

  3. On the View menu, click Code.

  4. Type the following text in the module's Declarations section:

          Option Compare Database
          Option Explicit
          Dim x as Form
    

  5. Close the Module window.

  6. Add a command button to the Customers form and set the following properties:

          Command Button:
    
             Name: OpenNewCust
             Caption: Open Customers
             OnClick: [Event Procedure]
    
    

  7. Click the Build button to the right of [Event Procedure] in the OnClick property of the command button, and then type the following procedure:

          Private Sub OpenNewCust_Click()
          Set x = New Form_Customers
          x.setfocus
          End Sub
    

  8. Close and save the Customers form.

  9. View the Customers form in Form view and click the command button. Note that a second instance of the Customers form opens.

REFERENCES

For more information about using the keyword "New" with a Set statement, search for "Set," and then "Set Statement" using the Microsoft Access 97 Help Index.


Additional query words: copy copies duplicate
Keywords : kbusage FmsHowTo
Version : 7.0 97
Platform : WINDOWS
Hardware : x86
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 24, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.