By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,679 Members | 2,069 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,679 IT Pros & Developers. It's quick & easy.

Working With Multiple Form Instances

P: n/a
"lyle" <ly************@gmail.comwrote in message
news:48**********************************@f3g2000h sg.googlegroups.com...
When I use multiple instances of forms it is through code like:

Dim ADetailForms(0 To 1) As [Form_Faculty Details]
Public Sub OpenSomeFormInstances()
Dim z As Long
For z = 0 To 1
Set ADetailForms(z) = New [Form_Faculty Details]
With ADetailForms(z)
.Visible = True
.Caption = "Look Ma Multiple Distinguishable Instances of
a Form " & z
End With
Next z
End Sub

Public Sub ZapAllThoseFormInstances()
Erase ADetailForms
End Sub
Question for you. I'm doing something similar, only, instead of opening the
forms all at once, I'm opening them as needed. I have a main form with
multiple records; and then I have a pop-up form that the user opens with
button. The pop-up form contains one record relating to the current record
in the main form (but from a different table).

Thus, the user is in a record in the main form; clicks the pop-up button.
The pop-up form opens with information for that record. The user then goes
to a different record in the main form; clicks the pop-up button, and a
second instance of the pop-up form opens with information about the second
record. And so on.

Now, all of this is working fine. The code I'm using is as follows:

Dim mfrmViewDescription() As Form_frmViewDescription

Private Sub cmdOpen_Click()

Dim i As Integer

ReDim Preserve mfrmViewDescription(UBound(mfrmViewDescription) + 1)
i = UBound(mfrmViewDescription)

Set mfrmViewDescription(i) = New Form_frmViewDescription
mfrmViewDescription(i).Visible = True

End Sub

My question is this. Since I'm using a dynamic array that grows each time
the user opens a form, will there be a resource issue. I have:

Erase mfrmViewDescription

in the Form_Close event, so that's fine. But, as long as the form is open,
the array will just keep growing.

Say, for example, that the user opens three instances of the form. The array
has three elements. They close all three instances, and then, sometime
later, while the main form is still open, they open another 4 instances. Now
the array has seven elements. And so on.

Two thoughts I have on this.

1) Re-use array elements by checking if the form corresponding to element 1,
element 2, etc., are still open. If not, then re-use that element. (Since
the array elements aren't used for anything except opening the form, it
doesn't seem like this would be a problem.) But how would I do that?

2) When the user closes the last of the open form instances, call Erase to
clear the array. That would be fine. But how would I know when the last form
was closed?

3) As a variation on (2): when the cmdOpen button is clicked, first check if
any instances of the form are open. And, if not, then call Erase before
opening the first instance. That would be fine. Except, as per (1), how
would I tell if an instance is open? (Although I guess here a general form
open routine would work, so maybe that's the answer).

Anyway, that's my situation. Any thoughts or ideas would be appreciated.
Thanks!

Neil
Nov 25 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Nov 25, 3:14 pm, "Neil" <nos...@nospam.netwrote:
"lyle" <lyle.fairfi...@gmail.comwrote in message

news:48**********************************@f3g2000h sg.googlegroups.com...
When I use multiple instances of forms it is through code like:
Dim ADetailForms(0 To 1) As [Form_Faculty Details]
Public Sub OpenSomeFormInstances()
Dim z As Long
For z = 0 To 1
Set ADetailForms(z) = New [Form_Faculty Details]
With ADetailForms(z)
.Visible = True
.Caption = "Look Ma Multiple Distinguishable Instances of
a Form " & z
End With
Next z
End Sub
Public Sub ZapAllThoseFormInstances()
Erase ADetailForms
End Sub

Question for you. I'm doing something similar, only, instead of opening the
forms all at once, I'm opening them as needed. I have a main form with
multiple records; and then I have a pop-up form that the user opens with
button. The pop-up form contains one record relating to the current record
in the main form (but from a different table).

Thus, the user is in a record in the main form; clicks the pop-up button.
The pop-up form opens with information for that record. The user then goes
to a different record in the main form; clicks the pop-up button, and a
second instance of the pop-up form opens with information about the second
record. And so on.

Now, all of this is working fine. The code I'm using is as follows:

Dim mfrmViewDescription() As Form_frmViewDescription

Private Sub cmdOpen_Click()

Dim i As Integer

ReDim Preserve mfrmViewDescription(UBound(mfrmViewDescription) + 1)
i = UBound(mfrmViewDescription)

Set mfrmViewDescription(i) = New Form_frmViewDescription
mfrmViewDescription(i).Visible = True

End Sub

My question is this. Since I'm using a dynamic array that grows each time
the user opens a form, will there be a resource issue. I have:

Erase mfrmViewDescription

in the Form_Close event, so that's fine. But, as long as the form is open,
the array will just keep growing.

Say, for example, that the user opens three instances of the form. The array
has three elements. They close all three instances, and then, sometime
later, while the main form is still open, they open another 4 instances. Now
the array has seven elements. And so on.

Two thoughts I have on this.

1) Re-use array elements by checking if the form corresponding to element 1,
element 2, etc., are still open. If not, then re-use that element. (Since
the array elements aren't used for anything except opening the form, it
doesn't seem like this would be a problem.) But how would I do that?

2) When the user closes the last of the open form instances, call Erase to
clear the array. That would be fine. But how would I know when the last form
was closed?

3) As a variation on (2): when the cmdOpen button is clicked, first check if
any instances of the form are open. And, if not, then call Erase before
opening the first instance. That would be fine. Except, as per (1), how
would I tell if an instance is open? (Although I guess here a general form
open routine would work, so maybe that's the answer).

Anyway, that's my situation. Any thoughts or ideas would be appreciated.
Thanks!

Neil
I guess you are creating a stack of sort_of_sub froms. And you don't
want the stack to get too high, lest it's components use too many
resources.
Off the top of my head I might try creating a dimensioned array of the
forms, let's say 0 to 9. And I'd use that with a counter. So the
counter would be zero when I opened the first sort_of_sub form and I'd
use the zeroeth element in the array. And I'd increment the counter.
Next opening the counter would be at one. So I'd use the oneth element
of the array. Hmmm. So what will I do when I get to ten? The array has
only (0 to 9) elements. Well if I Use Counter Mod 10 instead of
Counter, then I'll just keep using the ten forms (array elements) over
and over, always closing the ten- ago form and reusing it. For
instance the thirteenth form opened would close the third (Element 2)
and use that instance of the form. So would the 23rd.
So I limit the number of open sort_of_sub forms to 10. I have a
predictable rule for what to open and what to close. And I don't have
to redim my array.
And at the end I can still erase the array and clean up all my
pointers.
Well, I'm trying to handicap some Woodbine races here while I write
this, so it may be total nonsense.
Nov 25 '07 #2

P: n/a

"lyle" <ly************@gmail.comwrote in message
news:51**********************************@b40g2000 prf.googlegroups.com...
On Nov 25, 3:14 pm, "Neil" <nos...@nospam.netwrote:
>"lyle" <lyle.fairfi...@gmail.comwrote in message

news:48**********************************@f3g2000 hsg.googlegroups.com...
When I use multiple instances of forms it is through code like:
Dim ADetailForms(0 To 1) As [Form_Faculty Details]
Public Sub OpenSomeFormInstances()
Dim z As Long
For z = 0 To 1
Set ADetailForms(z) = New [Form_Faculty Details]
With ADetailForms(z)
.Visible = True
.Caption = "Look Ma Multiple Distinguishable Instances of
a Form " & z
End With
Next z
End Sub
Public Sub ZapAllThoseFormInstances()
Erase ADetailForms
End Sub

Question for you. I'm doing something similar, only, instead of opening
the
forms all at once, I'm opening them as needed. I have a main form with
multiple records; and then I have a pop-up form that the user opens with
button. The pop-up form contains one record relating to the current
record
in the main form (but from a different table).

Thus, the user is in a record in the main form; clicks the pop-up button.
The pop-up form opens with information for that record. The user then
goes
to a different record in the main form; clicks the pop-up button, and a
second instance of the pop-up form opens with information about the
second
record. And so on.

Now, all of this is working fine. The code I'm using is as follows:

Dim mfrmViewDescription() As Form_frmViewDescription

Private Sub cmdOpen_Click()

Dim i As Integer

ReDim Preserve mfrmViewDescription(UBound(mfrmViewDescription) + 1)
i = UBound(mfrmViewDescription)

Set mfrmViewDescription(i) = New Form_frmViewDescription
mfrmViewDescription(i).Visible = True

End Sub

My question is this. Since I'm using a dynamic array that grows each time
the user opens a form, will there be a resource issue. I have:

Erase mfrmViewDescription

in the Form_Close event, so that's fine. But, as long as the form is
open,
the array will just keep growing.

Say, for example, that the user opens three instances of the form. The
array
has three elements. They close all three instances, and then, sometime
later, while the main form is still open, they open another 4 instances.
Now
the array has seven elements. And so on.

Two thoughts I have on this.

1) Re-use array elements by checking if the form corresponding to element
1,
element 2, etc., are still open. If not, then re-use that element. (Since
the array elements aren't used for anything except opening the form, it
doesn't seem like this would be a problem.) But how would I do that?

2) When the user closes the last of the open form instances, call Erase
to
clear the array. That would be fine. But how would I know when the last
form
was closed?

3) As a variation on (2): when the cmdOpen button is clicked, first check
if
any instances of the form are open. And, if not, then call Erase before
opening the first instance. That would be fine. Except, as per (1), how
would I tell if an instance is open? (Although I guess here a general
form
open routine would work, so maybe that's the answer).

Anyway, that's my situation. Any thoughts or ideas would be appreciated.
Thanks!

Neil

I guess you are creating a stack of sort_of_sub froms. And you don't
want the stack to get too high, lest it's components use too many
resources.
Off the top of my head I might try creating a dimensioned array of the
forms, let's say 0 to 9. And I'd use that with a counter. So the
counter would be zero when I opened the first sort_of_sub form and I'd
use the zeroeth element in the array. And I'd increment the counter.
Next opening the counter would be at one. So I'd use the oneth element
of the array. Hmmm. So what will I do when I get to ten? The array has
only (0 to 9) elements. Well if I Use Counter Mod 10 instead of
Counter, then I'll just keep using the ten forms (array elements) over
and over, always closing the ten- ago form and reusing it. For
instance the thirteenth form opened would close the third (Element 2)
and use that instance of the form. So would the 23rd.
So I limit the number of open sort_of_sub forms to 10. I have a
predictable rule for what to open and what to close. And I don't have
to redim my array.
And at the end I can still erase the array and clean up all my
pointers.
Well, I'm trying to handicap some Woodbine races here while I write
this, so it may be total nonsense.

In my case, it's not really an issue of too many forms being open at once. I
can't imagine the user needing to open more than 3 or 4 at a time. The
problem is that when they close the form, the array elements wouldn't get
cleared. So the array would just keep getting bigger and bigger, even though
the form each element refers to is closed. So:

1) Is it a problem to let the array get larger and larger, if there are only
a few forms open at a time, and the previous array elements all refer to
forms that have been closed?

2) Is there a way to tell if an array element refers to a form that's still
open, so that, if it doesn't, I can reuse that array element?

3) Or, is there a way to tell when all forms have been closed, so I can just
use Erase?

The way the user will be using this is: one a form; go to another record;
open another form; go to another record; open a form; close one of the open
forms; go to another record; open another form; then close all forms; then,
sometime later, open another form; etc.

In other words, the number of forms open will go up and down, from zero to
probably about 3 or 4. But they won't all be open and closed at the same
time or in sequence. The user may not need the form that was open 3rd in
sequence anymore, and close it, but still leave #1 open; and so on.

So I think the above 3 questions would address handling of the resources
related to this issue.

Thanks!

Neil
Nov 25 '07 #3

P: n/a
Neil wrote:
"lyle" <ly************@gmail.comwrote in message
news:51**********************************@b40g2000 prf.googlegroups.com...
>On Nov 25, 3:14 pm, "Neil" <nos...@nospam.netwrote:
>>"lyle" <lyle.fairfi...@gmail.comwrote in message

news:48**********************************@f3g200 0hsg.googlegroups.com...

When I use multiple instances of forms it is through code like:
Dim ADetailForms(0 To 1) As [Form_Faculty Details]
Public Sub OpenSomeFormInstances()
Dim z As Long
For z = 0 To 1
Set ADetailForms(z) = New [Form_Faculty Details]
With ADetailForms(z)
.Visible = True
.Caption = "Look Ma Multiple Distinguishable Instances of
a Form " & z
End With
Next z
End Sub
Public Sub ZapAllThoseFormInstances()
Erase ADetailForms
End Sub
Question for you. I'm doing something similar, only, instead of opening
the
forms all at once, I'm opening them as needed. I have a main form with
multiple records; and then I have a pop-up form that the user opens with
button. The pop-up form contains one record relating to the current
record
in the main form (but from a different table).

Thus, the user is in a record in the main form; clicks the pop-up button.
The pop-up form opens with information for that record. The user then
goes
to a different record in the main form; clicks the pop-up button, and a
second instance of the pop-up form opens with information about the
second
record. And so on.

Now, all of this is working fine. The code I'm using is as follows:

Dim mfrmViewDescription() As Form_frmViewDescription

Private Sub cmdOpen_Click()

Dim i As Integer

ReDim Preserve mfrmViewDescription(UBound(mfrmViewDescription) + 1)
i = UBound(mfrmViewDescription)

Set mfrmViewDescription(i) = New Form_frmViewDescription
mfrmViewDescription(i).Visible = True

End Sub

My question is this. Since I'm using a dynamic array that grows each time
the user opens a form, will there be a resource issue. I have:

Erase mfrmViewDescription

in the Form_Close event, so that's fine. But, as long as the form is
open,
the array will just keep growing.

Say, for example, that the user opens three instances of the form. The
array
has three elements. They close all three instances, and then, sometime
later, while the main form is still open, they open another 4 instances.
Now
the array has seven elements. And so on.

Two thoughts I have on this.

1) Re-use array elements by checking if the form corresponding to element
1,
element 2, etc., are still open. If not, then re-use that element. (Since
the array elements aren't used for anything except opening the form, it
doesn't seem like this would be a problem.) But how would I do that?

2) When the user closes the last of the open form instances, call Erase
to
clear the array. That would be fine. But how would I know when the last
form
was closed?

3) As a variation on (2): when the cmdOpen button is clicked, first check
if
any instances of the form are open. And, if not, then call Erase before
opening the first instance. That would be fine. Except, as per (1), how
would I tell if an instance is open? (Although I guess here a general
form
open routine would work, so maybe that's the answer).

Anyway, that's my situation. Any thoughts or ideas would be appreciated.
Thanks!

Neil
I guess you are creating a stack of sort_of_sub froms. And you don't
want the stack to get too high, lest it's components use too many
resources.
Off the top of my head I might try creating a dimensioned array of the
forms, let's say 0 to 9. And I'd use that with a counter. So the
counter would be zero when I opened the first sort_of_sub form and I'd
use the zeroeth element in the array. And I'd increment the counter.
Next opening the counter would be at one. So I'd use the oneth element
of the array. Hmmm. So what will I do when I get to ten? The array has
only (0 to 9) elements. Well if I Use Counter Mod 10 instead of
Counter, then I'll just keep using the ten forms (array elements) over
and over, always closing the ten- ago form and reusing it. For
instance the thirteenth form opened would close the third (Element 2)
and use that instance of the form. So would the 23rd.
So I limit the number of open sort_of_sub forms to 10. I have a
predictable rule for what to open and what to close. And I don't have
to redim my array.
And at the end I can still erase the array and clean up all my
pointers.
Well, I'm trying to handicap some Woodbine races here while I write
this, so it may be total nonsense.


In my case, it's not really an issue of too many forms being open at once. I
can't imagine the user needing to open more than 3 or 4 at a time. The
problem is that when they close the form, the array elements wouldn't get
cleared. So the array would just keep getting bigger and bigger, even though
the form each element refers to is closed. So:

1) Is it a problem to let the array get larger and larger, if there are only
a few forms open at a time, and the previous array elements all refer to
forms that have been closed?

2) Is there a way to tell if an array element refers to a form that's still
open, so that, if it doesn't, I can reuse that array element?

3) Or, is there a way to tell when all forms have been closed, so I can just
use Erase?

The way the user will be using this is: one a form; go to another record;
open another form; go to another record; open a form; close one of the open
forms; go to another record; open another form; then close all forms; then,
sometime later, open another form; etc.

In other words, the number of forms open will go up and down, from zero to
probably about 3 or 4. But they won't all be open and closed at the same
time or in sequence. The user may not need the form that was open 3rd in
sequence anymore, and close it, but still leave #1 open; and so on.

So I think the above 3 questions would address handling of the resources
related to this issue.

Thanks!

Neil

Couldn't you record in the form instance what index into the array it
represents. If so then you could put a close event to mark they array
element as unused.

Bob
Nov 25 '07 #4

P: n/a

"Bob Alston" <bo********@yahoo.comwrote in message
news:JA**************@newsfe07.lga...
Neil wrote:
>"lyle" <ly************@gmail.comwrote in message
news:51**********************************@b40g200 0prf.googlegroups.com...
>>On Nov 25, 3:14 pm, "Neil" <nos...@nospam.netwrote:
"lyle" <lyle.fairfi...@gmail.comwrote in message

news:48**********************************@f3g20 00hsg.googlegroups.com...

When I use multiple instances of forms it is through code like:
Dim ADetailForms(0 To 1) As [Form_Faculty Details]
Public Sub OpenSomeFormInstances()
Dim z As Long
For z = 0 To 1
Set ADetailForms(z) = New [Form_Faculty Details]
With ADetailForms(z)
.Visible = True
.Caption = "Look Ma Multiple Distinguishable Instances of
a Form " & z
End With
Next z
End Sub
Public Sub ZapAllThoseFormInstances()
Erase ADetailForms
End Sub
Question for you. I'm doing something similar, only, instead of opening
the
forms all at once, I'm opening them as needed. I have a main form with
multiple records; and then I have a pop-up form that the user opens
with
button. The pop-up form contains one record relating to the current
record
in the main form (but from a different table).

Thus, the user is in a record in the main form; clicks the pop-up
button.
The pop-up form opens with information for that record. The user then
goes
to a different record in the main form; clicks the pop-up button, and a
second instance of the pop-up form opens with information about the
second
record. And so on.

Now, all of this is working fine. The code I'm using is as follows:

Dim mfrmViewDescription() As Form_frmViewDescription

Private Sub cmdOpen_Click()

Dim i As Integer

ReDim Preserve mfrmViewDescription(UBound(mfrmViewDescription) + 1)
i = UBound(mfrmViewDescription)

Set mfrmViewDescription(i) = New Form_frmViewDescription
mfrmViewDescription(i).Visible = True

End Sub

My question is this. Since I'm using a dynamic array that grows each
time
the user opens a form, will there be a resource issue. I have:

Erase mfrmViewDescription

in the Form_Close event, so that's fine. But, as long as the form is
open,
the array will just keep growing.

Say, for example, that the user opens three instances of the form. The
array
has three elements. They close all three instances, and then, sometime
later, while the main form is still open, they open another 4
instances. Now
the array has seven elements. And so on.

Two thoughts I have on this.

1) Re-use array elements by checking if the form corresponding to
element 1,
element 2, etc., are still open. If not, then re-use that element.
(Since
the array elements aren't used for anything except opening the form, it
doesn't seem like this would be a problem.) But how would I do that?

2) When the user closes the last of the open form instances, call Erase
to
clear the array. That would be fine. But how would I know when the last
form
was closed?

3) As a variation on (2): when the cmdOpen button is clicked, first
check if
any instances of the form are open. And, if not, then call Erase before
opening the first instance. That would be fine. Except, as per (1), how
would I tell if an instance is open? (Although I guess here a general
form
open routine would work, so maybe that's the answer).

Anyway, that's my situation. Any thoughts or ideas would be
appreciated.
Thanks!

Neil
I guess you are creating a stack of sort_of_sub froms. And you don't
want the stack to get too high, lest it's components use too many
resources.
Off the top of my head I might try creating a dimensioned array of the
forms, let's say 0 to 9. And I'd use that with a counter. So the
counter would be zero when I opened the first sort_of_sub form and I'd
use the zeroeth element in the array. And I'd increment the counter.
Next opening the counter would be at one. So I'd use the oneth element
of the array. Hmmm. So what will I do when I get to ten? The array has
only (0 to 9) elements. Well if I Use Counter Mod 10 instead of
Counter, then I'll just keep using the ten forms (array elements) over
and over, always closing the ten- ago form and reusing it. For
instance the thirteenth form opened would close the third (Element 2)
and use that instance of the form. So would the 23rd.
So I limit the number of open sort_of_sub forms to 10. I have a
predictable rule for what to open and what to close. And I don't have
to redim my array.
And at the end I can still erase the array and clean up all my
pointers.
Well, I'm trying to handicap some Woodbine races here while I write
this, so it may be total nonsense.


In my case, it's not really an issue of too many forms being open at
once. I can't imagine the user needing to open more than 3 or 4 at a
time. The problem is that when they close the form, the array elements
wouldn't get cleared. So the array would just keep getting bigger and
bigger, even though the form each element refers to is closed. So:

1) Is it a problem to let the array get larger and larger, if there are
only a few forms open at a time, and the previous array elements all
refer to forms that have been closed?

2) Is there a way to tell if an array element refers to a form that's
still open, so that, if it doesn't, I can reuse that array element?

3) Or, is there a way to tell when all forms have been closed, so I can
just use Erase?

The way the user will be using this is: one a form; go to another record;
open another form; go to another record; open a form; close one of the
open forms; go to another record; open another form; then close all
forms; then, sometime later, open another form; etc.

In other words, the number of forms open will go up and down, from zero
to probably about 3 or 4. But they won't all be open and closed at the
same time or in sequence. The user may not need the form that was open
3rd in sequence anymore, and close it, but still leave #1 open; and so
on.

So I think the above 3 questions would address handling of the resources
related to this issue.

Thanks!

Neil
Couldn't you record in the form instance what index into the array it
represents. If so then you could put a close event to mark they array
element as unused.

Bob
Yes, I suppose I could do something with global variables, and set a flag
when the form is closed. I was hoping for something more straightforward,
though. Thanks,

Neil
Nov 26 '07 #5

P: n/a
An interesting side-note here. I call this code to open multiple instances
of a form from two main forms -- one more complex than the other. In both
forms I had Erase mfrmViewDescription in the Form_Close event (where
mfrmViewDescription is the array holding the form objects). In the simpler
main form it worked fine. In the more complex main form, every time I closed
the form, Access would crash with a GPF. Same data opened in both forms;
same code to erase the array; yet one form crashed every time, and the other
form didn't.

I found that by looping through the array and explicitly setting each
element to Nothing before calling Erase, that it resolved the problem. The
more complex form didn't crash anymore.

So I thought you'd find that interesting. According to online help, Erase
does set each element to nothing before reallocating the space for dynamic
arrays. But, apparently, Erase needs a little help there.....

Neil
Nov 26 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.