1

I know Access forms have a property called parent, so is there any way of referencing their children? Ideally something like:

Forms!frmParentForm.Children

serverpunk
  • 10,665
  • 15
  • 61
  • 95

2 Answers2

3

You can cycle through a Form's Controls collection and determine the type of control as follows:

Dim f As Form
Set f = Forms!MyForm
Dim ctl As Control
For Each ctl In f.Controls
  If TypeOf ctl Is SubForm Then
    MsgBox "subform: " & ctl.Name
  ElseIf TypeOf ctl Is TextBox Then
    MsgBox "Textbox: " & ctl.Name
  Else
     ' test for more control types / do something
  End If
Next
ron tornambe
  • 10,452
  • 7
  • 33
  • 60
1

All of the controls on a form are "children" of that form and can be referenced by name, as in Me.Text1 for a text box. If you're looking for forms that are children of other forms by virtue of their being used in a Subform control then you could find them by enumerating the controls on the parent form, identifying the Subform controls (.ControlType=112), and then retrieving their .SourceObject property values.

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
  • 1
    This may also help for enumerating all controls, including those of subforms: http://stackoverflow.com/questions/3344649/how-to-loop-through-all-controls-in-a-form-including-controls-in-a-subform-ac – ta.speot.is Apr 23 '13 at 00:48