Find subform control name

T

Travis

I created a form with several tabs which contains a subform. I'm trying to
find the name of the subform control on each tab, how does one go about
retriving this information? I changed the name of the subforms to corrispond
to the form it references (ie. Form Name: FrmCustInfo, Subform Name:
SfmCustInfo). Trying to create a code to set focus on a different subform to
retrive data in a text box.
 
A

Allen Browne

You can examine the Parent property of a control. It will be page if it is
sitting on a tab page, or the form if it is sitting directly on the control.
(It could also be other things, e.g. for an attached label, or in an option
group.)

This example returns the PageIndex of the tab page if the control you pass
in (subform control in your case) is in the tab control, or -1 if it is
sitting directly on the form:

Function ParentNumber(ctl As Control) As Integer
On Error Resume Next
'Purpose: Return the PageIndex of the tab page that the control is on.
'Return: -1 if setting directly on the form, else the page of the tab
control.
'Note: Does not work for labels or controls in an option group.
Dim iReturn As Integer

iReturn = ctl.Parent.PageIndex
If Err.Number <> 0& Then
iReturn = -1
End If
ParentNumber = iReturn
End Function
 

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