Need list of all loaded forms

  • Thread starter Thread starter Sam
  • Start date Start date
S

Sam

Hello,

is there a method for gotting a list of all currently
loaded forms? the IsLoaded function only returns my parent
form but I need to know what subforms are loaded as well.

Thanks in advance!
Sam
 
You have to remember that a sub-form is NOT a form. You can place the SAME
sub form 10 times on the same form.

In other words, a sub-form is really what you call a sub-form "control". It
is not a logical concept to think of a sub-form as a form that is "loaded".

In fact, I wrote a calendar control, and each date box was a sub-form. That
means I had 31 sub-forms, and all 31 sub-forms were the SAME form.

So, in my example, is the sub-form loaded once, or 31 times? Sub-forms are
really just like any other control. However, this sub-form does in fact make
a new instance of the form it is referencing.

When you load a form, it becomes part of the forms collection

for each Vform in forms
debug.Print Vform.name
next Vform

I mean, it is not quite clear why you need to know/test that a sub-form is
being used?

If the main form is loaded, then is not the sub-form loaded?

If you must, you could scan each contorl on a form, and check for a sub-form
contorl. When you find the sub-form contorl, then you can check what form
name is the source of that control.

Perhaps you might ask for assistance on the problem you are tying to solve
and not ask how to check if a sub-form exists on a form?
 
I see your point. Okay, here's the deal, I use a multitude
of lookup tables as the row sources for all of my combo
boxes. To make a long story short I would like to requery
all combo boxes on both the loaded form and all of it's
subforms at once so that if a user adds values to the
lookup tables those values will be available without
closing and reopening the form. I'm calling the following
sub routine for the form and it works great but I'm at a
loss as to how to handle the subforms.

Public Function RequeryDDLs(frm As Object)
Dim ctl As Control
'Reset control to null
For Each ctl In frm.Controls
With ctl
Select Case .ControlType
Case acComboBox, acListBox
ctl.Requery
End Select
End With
Next
End Function

I really appreciate the help.

Thanks!
Sam
 
Why not just requery the form. If you requery the form, then all combo in
the form,a and the sub-form will re-load.

So, if you go:

me.Requery

In the form, then the sub-form stuff will get re-loaded for you.
 
I have tried Me.Requery but it does not requery the combo
box row sources. Me.Refresh does not work either. I've
even tried explicitly requerying the subform (ie. Forms!
Form1!Subform1.Requery) with negative results.
 
Sam said:
I see your point. Okay, here's the deal, I use a multitude
of lookup tables as the row sources for all of my combo
boxes. To make a long story short I would like to requery
all combo boxes on both the loaded form and all of it's
subforms at once so that if a user adds values to the
lookup tables those values will be available without
closing and reopening the form. I'm calling the following
sub routine for the form and it works great but I'm at a
loss as to how to handle the subforms.

Public Function RequeryDDLs(frm As Object)
Dim ctl As Control
'Reset control to null
For Each ctl In frm.Controls
With ctl
Select Case .ControlType
Case acComboBox, acListBox
ctl.Requery
End Select
End With
Next
End Function

I really appreciate the help.

Sounds like you could use this function I wrote to answer a similar
newsgroup question a year or so ago.

'----- start of code -----
Public Function fRequeryRowSources(frm As Form)

' Requery all combo and list boxes on the argument form
' and on any subforms it may contain, and any of their
' subforms, and so on.

Dim ctl As Control

With frm
For Each ctl In .Controls
Select Case ctl.ControlType
Case acListBox, acComboBox
ctl.Requery
Case acSubform
If Len(ctl.SourceObject) > 0 Then
fRequeryRowSources ctl.Form
End If
End Select
Next ctl
End With

End Function

'----- end of code -----
 
That worked great! Thanks!!

-----Original Message-----


Sounds like you could use this function I wrote to answer a similar
newsgroup question a year or so ago.

'----- start of code -----
Public Function fRequeryRowSources(frm As Form)

' Requery all combo and list boxes on the argument form
' and on any subforms it may contain, and any of their
' subforms, and so on.

Dim ctl As Control

With frm
For Each ctl In .Controls
Select Case ctl.ControlType
Case acListBox, acComboBox
ctl.Requery
Case acSubform
If Len(ctl.SourceObject) > 0 Then
fRequeryRowSources ctl.Form
End If
End Select
Next ctl
End With

End Function

'----- end of code -----

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


.
 
Back
Top