Get Active SubForm Name

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've searched the groups and can't find the specific answer to this.

I have a main form wherein there are multiple hidden subs that individually
become visible (all others go invisible) depending on what combo item is
selected.

On my main form I have a series of record navigation buttons. When I select
Next I want to grab the name of the currently active subform on the main form
and set the focus back to that subform (as the focus shifted to the main form
when I clicked the button!).

Surely there is a way of pulling the currently visible subform control name
so I can reference it.

Any help is appreciated!
 
When the button it clicked it (the command button) is the active control.
But if focus was previously in a subform, then Screen.PreviousControl should
give you what you need.

If only one subform is visible, an alternative would be to loop through the
controls on the form to find one of type acSubform that has its Visible =
True. This kind of thing:
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acSubform Then
If ctl.Visible Then
MsgBox "The visible subform control is called " & ctl.Name
Exit For
End If
End If
Next
 
Since you have code that set the visibility of the subform dependent on the
value of the combobox, can't you use the code there to store the current
subform control name and use that. Or model a routine to get the subform
name based on the code.

Other that that you could step through all the controls on the main form and
check the visible property of the subform controls.
 
Thanks to both!

John Spencer said:
Since you have code that set the visibility of the subform dependent on the
value of the combobox, can't you use the code there to store the current
subform control name and use that. Or model a routine to get the subform
name based on the code.

Other that that you could step through all the controls on the main form and
check the visible property of the subform controls.
 
Back
Top