My Forms Collection

J

Joe Cletcher

I want to create a collection of forms that maintains the state of the form.
I plan to add the form to the collection, then close the form before I move
onto the next form selected by the user. I think I can do that. However, when
I want to return to a form at it's saved state in the collection, I don't
know how to open and show the form.

the following doesn't work
docmd.opeform "form name string"

docmd.openform mycollection(3) won't work

can I

set aform = mycollection(3)
aform.visible

I've never been able to do the above in VBA. No problem in VB.NET
 
G

George Nicholson

What *exactly* are you adding to the collection, an access object, a form
object or the form name?

If form object:
docmd.openform mycollection(3).Name
that should work as long as the form is open, but makes little sense if it's
open...
"A Form object is a member of the Forms collection, which is a collection of
all currently open forms."
My guess is that if you are adding a Form object to a collection and then
close the form, your collection now contains Nothing.

If an Access object (from the AllForms collection)
docmd.openform mycollection(3).Name
should work.

If form name:
docmd.openform mycollection(3)
should work
set aform = mycollection(3)
aform.visible

As above: if aform is a Form object, and open, that should work. If it
isn't, it won't. One major difference between VB forms and Access is how
they can be opened. I have a vague recollection that setting a VB form's
Visible property automatically invoked Show/Load, if necessary (or something
like that). Whether that is the case or not, Access forms won't behave that
way, you have to explicitly open them, no shortcuts.

HTH,
 
J

Joe Cletcher

I plan on putting an Access form object in the collection. The real problem
is I can't seem to open a second copy of a form in Access. My form displays
parts (parent parts) that may or may not be made up of other piece parts. The
piece parts are shown in a sub-form--there are several sub-forms. I want to
be able to double-click on a piece part and show it as the parent part with
any of its piece parts. I can do this, but as soon as I do the form that
displays the original parent part is replaced with the new parent (elevated
piece part).

I was hoping that in the "Before Close" event that I could store the
original parent form object in a collection and then let the form continue to
close; then let Access replace the original parent form with the elevated
piece part to parent form.

Is all that clear as mud.

My choice may be to create a class and then a collection of this class with
the information needed to open the original form in it's initial state. I
would like to create a stack of the forms opened by the user, let them choose
any form to return to and continue from there. Methods for this "stack" class
would include "Pop, "Push", "Top" and "Empty" which are standard stack
methods. Of course, that may require a second class to hold a collection with
the stack methods. Rather that program all those "classes", a collection has
the methods (different names but same functionality) and would save a great
deal of effort trying to figure out how to write a "Collection" class in VBA.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top