Wednesday, January 4, 2012

Managing Multiple Form Instances

Need: Multiple Form Instances

Have you ever needed to create/compare/edit multiple records at the same time?  If so, you've probably noticed that the default form behavior in access is to allow one instance of each form to be open at any given time.  This limits the user to working with one record at a time in "Single Form" view.  The good news is that there are a few different ways of adding and managing multiple instances of a form and this article will cover the method most commonly utilized for my projects.

Solution: Collection Method

This example will use two forms (frmMain and frmPersonsDetail) and three(3) modules outlined below.

modInstanceCollection

This module contains functions necessary for managing instances of the person form.

  • Function OpenNewRecordFormInstance() - Create "New Record" form instance.
  • Function OpenFormInstance(Optional lngID As Long) - Create form instance.
  • Function CloseInstanceCollection() - Close all instances in form collection
  • Function CloseInstanceHwnd(lngHwnd As Long) As Boolean - Close specified instance based on form's window handle.
  • Function CloseInstanceID(lngID As Long) As Boolean - Alternative method to close specified instance based on record's ID.
modSetParent

This module is used to set each new instance of the person form as a child of the main form.  The purpose of demonstrating this functionality is to prevent the person forms from disappearing behind the main form when the lose focus.  Utilizing this method can be especially beneficial for applications using a form as the basis of a custom user interface.

modInstancePosition

This module contains functions for managing the opening position of form instances.  This is used to prevent each concurrent form instance from being opened directly on top of to previous instance.

A functional example database can be found at this link: Multi-Instance Form Management, or on the AccessInsider Examples Page.

Comments have been included with the example code as to provide the readers with a better understanding of the methods used.

0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More