Mulitple instances of Forms

G

Guest

I have implemented Allen Browne's excellent method to handle opening multiple
instances of the same form:
http://allenbrowne.com/ser-35.html

Question though around referencing the form. I can open the form and
populate an unbound text bound located on the main form to hold the record ID
which each suform uses as a filter. But how can I reference the ID in this
text box for a subform nested one level deeper i.e a subform on a subform?

As an example, suppose the main form is a company, then one subform is
countries, then a further nested subform is office locations. How can the
office locations subform reference the country ID stored in the text box on
the main form?

Pls tell there is a simple solution that potentially uses something like the
unique windows handle (hwnd) of the main form!

Many thanks for anyone's thoughts
/JW
 
A

Allen Browne

Within the context of that form, subform and their modules, you don't need
to worry about the multiple instances, because you already have the
reference, e.g.:
- Me (the form itself, main or sub);
- Me.[Sub1].Form (referring to the subform from the main form);
- Me.Parent (referring to the main form from the subform.)

From elsewhere, you need to refer to them through the Forms collection. The
reference:
Forms!Form1
is ambiguous if there are multiple instances of Form1 available, so you need
to use the index number to refer to it, e.g.:
Forms(7)

Of couse, which one is the 8th form is constantly changing (e.g. if Forms(2)
is closed). But it's dead easy and quick to loop through the Forms
collection until you hit the one that has the hWndy you want:
For i = 0 to Forms.Count -1
If Forms(i).hWnd = 9999 Then
'you found the right instance to work with
 
G

Guest

Thanks Allen. Late last night, I tripped over the parent function and used
it successfully to 'feed' the record ID to subsequent (ie. embedded) subforms
and all works well. Cheers for your assistance. Greatly appreciated
/JW

Allen Browne said:
Within the context of that form, subform and their modules, you don't need
to worry about the multiple instances, because you already have the
reference, e.g.:
- Me (the form itself, main or sub);
- Me.[Sub1].Form (referring to the subform from the main form);
- Me.Parent (referring to the main form from the subform.)

From elsewhere, you need to refer to them through the Forms collection. The
reference:
Forms!Form1
is ambiguous if there are multiple instances of Form1 available, so you need
to use the index number to refer to it, e.g.:
Forms(7)

Of couse, which one is the 8th form is constantly changing (e.g. if Forms(2)
is closed). But it's dead easy and quick to loop through the Forms
collection until you hit the one that has the hWndy you want:
For i = 0 to Forms.Count -1
If Forms(i).hWnd = 9999 Then
'you found the right instance to work with

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

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

J Welsby said:
I have implemented Allen Browne's excellent method to handle opening
multiple
instances of the same form:
http://allenbrowne.com/ser-35.html

Question though around referencing the form. I can open the form and
populate an unbound text bound located on the main form to hold the record
ID
which each suform uses as a filter. But how can I reference the ID in
this
text box for a subform nested one level deeper i.e a subform on a subform?

As an example, suppose the main form is a company, then one subform is
countries, then a further nested subform is office locations. How can the
office locations subform reference the country ID stored in the text box
on
the main form?

Pls tell there is a simple solution that potentially uses something like
the
unique windows handle (hwnd) of the main form!

Many thanks for anyone's thoughts
/JW
 

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