Multiple Form Instances in an Array

KeithWilliams

Registered User.
Local time
Today, 20:06
Joined
Feb 9, 2004
Messages
137
Hi,

I would like to open multiple instances of a form simultaneously, independent of each other.

I checked out the information on this thread: http://www.access-programmers.co.uk/forums/showthread.php?t=49847

The KB article referenced seems to depend on recursive references from one form to the next in a "chain", so the user breaking the chain by closing one of the forms would cause all instances below it in the chain to be closed.

I want to create instances that are independent of each other, and this is what I tried:

(In a module)
Global gf_form(100) As Form
Global gint_formCount As Integer

(In the script where I create the instances)
<loop condition>
Set gf_form(gint_formCount) = New Form_F_Debrief
DoCmd.OpenForm gf_form(gint_formCount).Name, , , "[IncidentNo]=" & intIncident & " AND [IncidentYear] = " & intYear
gint_formCount = gint_formCount + 1
<end of loop>

However, the OpenForm command appears to just apply the latest criteria to the existing form, rather than creating another instance, so I always end up with just one instance of Form_F_Debrief open.

I know this approach works in other programming languages, so I'm puzzled what Access has against it!

Is there a way of opening multiple instances without employing the recursion trick and suffering its limitations?

Many thanks,
Keith.
 
After playing around with multiple instances of the same form for a couple of days now,

Set gf_form(gint_formCount) = New Form_F_Debrief

does create a new form in the forms collection; it's just not visible.

So instead of:

DoCmd.OpenForm gf_form(gint_formCount).Name, , , "[IncidentNo]=" & intIncident & " AND [IncidentYear] = " & intYear

Do:

gf_form(gint_formCount).Visible = True

A big problem I encountered is that each instance of a form in the forms collection has the same name. So where ever you need to refer to a form by name (like in the underlying query), you're going to have problems (at least I am).

You have to reference the instance of the form you want by the instance of the form that has the focus, or by the references in the form array: anything but the name of the form because there could be n number of forms in the Form collection that all have the same Name.

AC97 Developers Handbook suggests creating a user defined collection where form references are added and removed as instances ofthe form are created or removed. And it's up to the designer (via VBA) to track that collection as form instances are created and removed.

For me, it gets really complicated when the form I want multiple instances of has a subform where the subforms underlying query is referencing controls on the main form AND where the query makes a function call that also references controls on the main form.

I'm trying to do that right now without using an explicit form name and have passed my wits end about 4 hours ago...
 
how did you tackle the problem of referring to a particular instance in the end?
 
Hi MrK,

DALeffler was right in his explanation, and his proposed solution is basically what I used, although I don't have time to review the code thoroughly (the original problem was some time ago!)

Keith.
 

Users who are viewing this thread

Back
Top Bottom