Using IsLoaded with a subform

  • Thread starter Thread starter SharynInCambodia
  • Start date Start date
S

SharynInCambodia

I have been using IsLoaded for detecting if a form is open and linking a
second form to the open main form (it sets the foreign key in the second form
using the primary key from the main form).

This works fine, but now i want to use it from a subform to another form and
the IsLoaded code is not working. if i open up the subform separately as a
plain form, the code works and does what i want, but as a subform it does
not.
Any ideas on how to get it working.
 
As you found, subforms are not open in their own right, so they are not part
of the Forms collection, and their IsLoaded property will not return True in
the AllForms collection.

If you really need to know this, you would need to:
a) Loop through the Forms collection, examining each in turn.
b) For each form, loop through its Controls collection.
c) For each control, if it is a subform control, examine its SourceObject to
see if it's the one you need.
d) Repeat steps (b) and (c) recursively (for the Form in the subform
control), so you handle nested subforms too.

That's not trivial to write. If the recursive part is new, here's an example
of a function that searches a form for subforms and calls itself
recursively:
http://allenbrowne.com/ser-56.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

message
news:[email protected]...
 
thanks allen for replying
maybe i'll just re-write and have it open as a linked form - looks complex
 
Back
Top