how can I programatically close a subform

  • Thread starter Thread starter Guest
  • Start date Start date
A subform is not "open" (not part of the Forms collection), so you cannot
open or close it.

You can hide it by toggling the Visible property of the subform control.

Or you can load/unload it by setting/clearing the SourceObject property of
the subform control. If you do set the SourceObject, Access will have a
guess at what you want for the LinkMasterFields/LinkChildFields, but it may
not be what you intend.
 
i have a related question that perhaps you can answer. At runtime, I create
a form and populate it with various controls, including one subform (for
which I also set the SourceObject property).

At the end of the sub which does all of this I have the command

DoCmd.Close acForm, frm.Name, acSaveYes

I was expecting the new form to be saved without a prompt, but I get a
prompt asking to save both the form and its embedded subform. If I don't add
the subform, I am not prompted.

Any ideas how to suppress the save prompt, which seems to be caused by the
subform?

thanks
 
You explicitly saved the main form.

If you created a subform as well, did you explicitly save that as well?
 
No. I add the subform with a line like;

Set ctl = CreateControl(frm.Name, acSubform, acDetail, , "", iLP, iTP, iWP,
iHP)

then I set its source object to an existing form;

ctl.SourceObject = "sfrmSubDisplay"

Then I modify some of the properties for controls on the subform with code
like;

frm.Controls(ctl.Name).Form.Controls("txt1").Width = 250

When complete I close the form with

DoCmd.Close acForm, frm.Name, acSaveYes

At runtime, when this line is processed, the prompt appears asking to save
both the form and subform. If I don't modify any of the control properties
on the subform, I don't get the prompt. If I add a DoCmd.SetWarnings False,
I don't get the prompt and any properties I've modified on the subform are
saved.

Should I just use the DoCmd.SetWarnings False to suppress the prompt? Or do
you recommend that I save the subform explicitly, and if so, can you give me
a code example?

Thanks
 
If turning off SetWarnings suppresses the warnings and gives the desired
results, just go ahead and do that.

(I can't say that I generate forms on the fly often, other than for
demonstration purposes, or creating Wizard-type interfaces. For commercial
applications, I always use an MDE.)
 
Back
Top