Adding a subform thru Visual Basic at runtime

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form used for writing general memorandums as part of a larger
database. I inserted a subform that will only be used once to organize a list
of items and their dollar values. It is hidden all other times. The subform
works great and organizes the memo instantly but is only used the one time.
The main memo form will be used frequently.

Instead of hiding it, is there a way through VB to insert the subform into
the main form for the one use ? I already have a button that is pressed to
unhide the subform and could put the code there but can't find an example. I
repeat this with a report/subreport to do the actual printing.
 
Rich said:
I have a form used for writing general memorandums as part of a larger
database. I inserted a subform that will only be used once to organize a list
of items and their dollar values. It is hidden all other times. The subform
works great and organizes the memo instantly but is only used the one time.
The main memo form will be used frequently.

Instead of hiding it, is there a way through VB to insert the subform into
the main form for the one use ? I already have a button that is pressed to
unhide the subform and could put the code there but can't find an example. I
repeat this with a report/subreport to do the actual printing.


No, adding controls is a design time operation. What you
have is the standard way to do this kind of thing.

The only alternative that comes to mind is to use another
separate form instead of a subform, but this involve some
additional form management code, especially if you are using
the Link Master/Child properties.
 
Thanks for your reply. What I have works great but I thought maybe the other
would be a possibility. There actually is not a Master/Child link. There is
only one view of the subform that is necessary so the link isn't needed.
 
That will make for less work to use a separate form, but I
still don't see a good reason to change what you've got now.
 
Actually, there is a way to create forms with modules at run time, then
attach them to another form as a sub form and then discard the subform and
delete it when you are done with it. This saves alot of space and can save
time as well.
The best thing I can tell you is to search the MS web site, that is where I
found the answer.



Marshall Barton said:
That will make for less work to use a separate form, but I
still don't see a good reason to change what you've got now.
--
Marsh
MVP [MS Access]


Rich said:
Thanks for your reply. What I have works great but I thought maybe the other
would be a possibility. There actually is not a Master/Child link. There is
only one view of the subform that is necessary so the link isn't needed.
 
Yes, there is a way, BUT the methods that are used only
operate in design view, are heavy duty operations that are
more complex and slower than just making controls visible
and if the changes are saved to the frontend mdb file,
greatly increase the chances of corrupting the file. In
addition to all that, those methods will be inoperative when
you get around to distributing your app as an mde file.
These methods are provided for the situation where you need
to create a design time wizard to assist in creating an
application, not for on-the-fly form manipulation.

You should cite the KB article that you are referring to as
an authority so specific points can be discussed.
 
Back
Top