Open Multiple Instances of a Form

Problem

In an application, you have a form showing information about a customer. You would like to be able to open another copy of the form so you could move to a different row, compare values, perhaps copy from one row to another, or just look at more than one customer’s record at once. As far as you can tell, you can have only one open copy of a form at a time.

Solution

In older versions of Access, you were limited to having only a single copy of a form open at any time. Starting with Access 95, you can open multiple instances of a form, under complete program control. There’s no user interface for this functionality, however, so you must write code to make it happen. This solution demonstrates how to create, handle, and delete multiple instances of a form using the New keyword and user-defined collections.

Follow these steps to convert your own forms to allow for multiple instances:

  1. Add two buttons to your form, with captions like Create New Instance (named cmdViewAnother in the example) and Delete All Extra Instances (named cmdCloseAll in the example).

  2. Add the following code to the Click event procedure of the Create New Instance button:

    Private Sub cmdViewAnother_Click(  )
       Call acbAddForm
    End Sub
  3. Add the following code to the Click event procedure of the Delete All Extra Instances button:

    Private Sub cmdCloseAll_Click(  )
       Call acbRemoveAllForms
    End Sub
  4. Add the following code to the Close event procedure for the form:

    Private Sub Form_Close( ...

Get Access Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.