Setting a subform's SourceObject to a member of a collection

  • Thread starter Dennis Snelgrove
  • Start date
D

Dennis Snelgrove

I'm using Access 2002 SP2. I've got a form which is primarily a shell - it's got a couple of command buttons, a listbox, and a large subform container.. The idea is that the database is an Event log in which the user may have to have several instances of the same form open at the same time. I'm setting it up so that the subform container will hold an entry form as a subform, and the listbox will be the device through which the user would change from one entry form to another. As an Event finishes, it gets saved and the listbox will lose the reference to that particular instance of the entry form. I'm using the tried and true method of making a new collection and adding the form to it as new Events happen and new instances are opened. We use several different entry forms depending on the situation.

The problem I'm having is that the subform container's SourceObject needs to have the name of the form being put in it, but the name of the forms in my collection are going be mostly the same, since we use multiple instances of the same form. I've tried to programmatically change the name of the form at the time it's created to insure that each form in the collection has aunique name, but I'm being told that the Name property is Read-only. The collection uses the hWnd value to index the forms, but I don't see how I canuse that to help me with setting the SourceObject property.

Has anyone got any suggestions? I know about the tabs ability in this version, but I'm avoiding those infavour of an interface that is much more controlled.

Thanks...
 
M

Marshall Barton

Dennis said:
I'm using Access 2002 SP2. I've got a form which is
primarily a shell - it's got a couple of command buttons,
a listbox, and a large subform container. The idea is
that the database is an Event log in which the user may
have to have several instances of the same form open
at the same time. I'm setting it up so that the subform
container will hold an entry form as a subform, and the
listbox will be the device through which the user would
change from one entry form to another. As an Event
finishes, it gets saved and the listbox will lose the
reference to that particular instance of the entry form.
I'm using the tried and true method of making a new
collection and adding the form to it as new Events
happen and new instances are opened. We use several
different entry forms depending on the situation.

The problem I'm having is that the subform container's
SourceObject needs to have the name of the form
being put in it, but the name of the forms in my collection
are going be mostly the same, since we use multiple
instances of the same form. I've tried to programmatically
change the name of the form at the time it's created to
insure that each form in the collection has a unique
name, but I'm being told that the Name property is
Read-only. The collection uses the hWnd value to index
the forms, but I don't see how I can use that to help me
with setting the SourceObject property.

Has anyone got any suggestions? I know about the tabs
ability in this version, but I'm avoiding those in favour of
an interface that is much more controlled.

Blast! I posted a long reply a couple of days ago, but it
seems to have dissappeared. I must have fumbled it when I
tried to send it. I'll try again and hope I can reconstruct
all my thoughts re your question.

The thing about what you tried by using a single subform
control is that you are NOT actually using multiple
instances of any form. When you set the subform control's
SourceObject property, the previous "instance" is unloaded
and a new "instance" is loaded. That can also cause
problems during the unloading if a record can not be saved
because it violates a validation rule.

You actually got an important clue about this when you could
not refer to the form that's currently displayed in the
subform control. The reason is that controls in the form
object currently displayed in a subform control are
referenced by going through the subform control without ever
mentioning the source object's name.

To do what I think you want to do, you can either:

Use real multiple instances of a form that are not used as
subforms. This is great except that you do not have a
decent way to specify where the form should be displayed, in
the Access window as normal forms or on the desktop for
popup forms; or

Your main form could have a large number of invisible
subform controls with no source object specified until you
need a new instance. Then choose one of the unoccupied
subform controls, set its Source Object, make the previous
subform control invisible and make the new instance visible.

Either way, you need a collection indexed by the event ID.
In the former scenario, a collection of form objects opened
via Set frm = New Form_formname. In the latter case, a
collection of subform controls.
 
M

Marshall Barton

Dennis said:
Actually, your original post came through fine; it was on the Microsoft forums. I posted the same question to both places within a couple minutes of each other. I prefer these newsgroups as they allow for specialization of what a poster's question pertains to, but Microsoft didn't ask me for my opinion and opened up their forums anyway...

I posted a reply there, so I won't go farther here except to say that if this all turns out to be unmanageable as I'm trying to do it, I'm going to give serious consideration to your idea using MoveSize. That's about as close what I'm attempting as I can think of...

Thanks and see you on the Microsoft forum.


Right, I just saw your response in the Answers forum so i
just lost track of where I posted. I did look for it there
before I posted here, but that stupid forum interface make
it difficult to find a thread unless I know exactly what I'm
lookin for.

Glad we can continue this in one place (Answers forum) so I
don't get any more confused than I am already ;-)
 

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