Finding a property

K

Kirk Wilson

What is the syntax to find the name property for:

subform name
on a page of multiple pages
on a tabcontrol
on a form

I know that there is a SubForm.Name but I cant figure out the proper syntax.

It seems to me that you should be able to use:

Forms!TabControl!Page!SubForm.Name

I know that name is a property of a control. I just don't understand the
logic in the hierarctical naming conventions especially with reference
to the "Me." identifier. I would appreciate a jink to a good reference.
 
B

BruceM via AccessMonster.com

Neither a tab control or tab pages affect how you reference a control. It is
as if you had drawn a box around a control. You don't need to reference the
box in order to reference the control.

When you write Forms! you are saying that the next thing is a member of the
Forms collection, so it needs to be a form name:

Forms!frmMain...

Next is a member of a collection pertaining to the form. In the case of a
subform, you need the name of the subform control (the "box" containing the
subform), which is a member of the form's Controls collection (along with
text boxes, combo boxes, check boxes, lines, etc.):

Forms!frmMain!SubformControlName

Next is a property of the subform control. It could be something like its
Visible property:

Forms!frmMain!SubformControlName.Visible = False

or it could be the Form property (i.e. the name of the form being used as the
subform, as opposed to the subform control) if you need to work with the form
rather than the subform control:

Forms!frmMain!SubformControlName.Form...

You can next refer to a property of the form itself:

Forms!frmMain!SubformControlName.Form.Name

or you can refer to a control on the form or a field in its Record Source,
both of which are members of collections pertaining to that form (the subform)
 
K

Kirk Wilson

All of the replies have been very interesting but aren't getting me where
I want to go.

I have a form with a multi page tab form on it. Each tab form page has a
single form on it. I am using the change event of the tab form to trigger
code. I know the tab name using the Pages(Index).Name property. What I
need to get programmatically is the subform name on that page & it's
record source.

It seems to me that the SubForm.Name & SubForm.RecordSource properties
are exactly what I need but I can't figure out the syntax.

I have no problem doing this explicitly. Unfortunately, my DB has 20 main
forms each having multi page tab forms and that makes for hard to
maintain code.
 
J

John W. Vinson

All of the replies have been very interesting but aren't getting me where
I want to go.

I have a form with a multi page tab form on it. Each tab form page has a
single form on it. I am using the change event of the tab form to trigger
code. I know the tab name using the Pages(Index).Name property. What I
need to get programmatically is the subform name on that page & it's
record source.

It seems to me that the SubForm.Name & SubForm.RecordSource properties
are exactly what I need but I can't figure out the syntax.

I have no problem doing this explicitly. Unfortunately, my DB has 20 main
forms each having multi page tab forms and that makes for hard to
maintain code.

Referencing a subform is *exactly the same* whether it's on a tabcontrol or
not. The tab Pages property is not used in the subform reference, only the
Name property of the Subform control:

Me!subformcontrol.Form.Recordsource
 
K

Kirk Wilson

I appreciate the reply.

I do not know the subformcontrol in advance. I need to programatically
get that information. I know the Main form name, the tabcontrol name,
and the page index. I need to use that information to get the
subformcontrol name and record source.

Help has a code snippet that lists objects for a page of a tabcontrol so
it is possible to identify controls that are a member of the (page
collection?). Unfortunately I can't modify the code to determine the
controls associated with a specific page. Once I can identify the
controls associated with a specific page (a solitary subform) i intend to
use that information to build an sql statement to programatically set the
record source.

My general understanding of the hierarchy is:

A form has a collection of controls
tabcontrol is a member of the form control collection
pages is a member of the tabcontrol control collection
page is a member of the pages control collection
subform is a member of the page control collection

The help snippet enumerates the members of the page control collection so
I should be able to identify an individual member by it index ie:

tabcontrol!pages(index)!control(index).name

Am I missing something?
 
J

Jeanette Cunningham

Here is some code that gets the name of a subform.
It only looks for one subform on any section of a form.
This code runs when the form is open in form view.

I think you want to get the subform names from a developers perspective,
when the form isn't in use.
Maybe you can adapt the below code for your purposes.

----------------------
Public Function GetOneSubfrmCtlName(frm As Form, _
strSection As String) As String
'gets the first subform it finds on a form section


Dim ctl As control
Dim strTxt As String
Dim lngSection As String

Select Case strSection
Case "Detail"
For Each ctl In frm.Section(0).Controls
If ctl.ControlType = acSubform Then
If ctl.Visible = True Then
strTxt = ctl.Name
Exit For
End If
End If
Next

Case "Header"
For Each ctl In frm.Section(1).Controls
If ctl.ControlType = acSubform Then
If ctl.Visible = True Then
strTxt = ctl.Name
Exit For
End If
End If
Next

Case "Footer"
For Each ctl In frm.Section(2).Controls
If ctl.ControlType = acSubform Then
If ctl.Visible = True Then
strTxt = ctl.Name
Exit For
End If
End If
Next

Case Else
End Select


If Len(strTxt & vbNullString) > 0 Then
GetOneSubfrmCtlName = strTxt
Else
GetOneSubfrmCtlName = ""
End If

End Function
 
J

John Spencer

I think you might want something like the following

Private Sub TabCtLPages_Change()
Dim ctl As Control
With Me.TabCtLPages.Pages(1)
For Each ctl In .Controls
If ctl.ControlType = acSubform Then
Debug.Print ctl.Name
End IF
Next ctl
End With
End Sub

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
 
J

John Spencer

Obviously, you need to change this line to reflect the correct page
With Me.TabCtLPages.Pages(1)

Probably this would work to get the current tab page
With Me.TabCtLPages.Pages(Me.TabCtl)


John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
 
K

Kirk Wilson

Thanks for the help John. I used the following & it worked like a champ.
Once I was able to get the Subform name everything else was easy.

The index in this function is the page value from the tabcontrol. I can
call this from any page on any tabcontrol form and it will return the
correct subform name. If I had more than one subform on a page i would
load them into an array and use the array index to identify each subform.

Public Function GetSubFormName(tabFormName As Control, Index As Integer)
As String

Dim ctl As Control
With tabFormName.Pages(Index)
For Each ctl In .Controls
If ctl.ControlType = acSubform Then
GetSubFormName = ctl.Name
End If
Next ctl
End With
End Function
 
B

BruceM via AccessMonster.com

I don't know if it will help in this instance, but one thing you can do in a
variety of situations is to use the Tag property of a control. Rather than
creating an array you could use the Tag value to identify the subform you
need. As I said, it may not offer any advantages in this instance, but in
general it can by a useful option.

Kirk said:
Thanks for the help John. I used the following & it worked like a champ.
Once I was able to get the Subform name everything else was easy.

The index in this function is the page value from the tabcontrol. I can
call this from any page on any tabcontrol form and it will return the
correct subform name. If I had more than one subform on a page i would
load them into an array and use the array index to identify each subform.

Public Function GetSubFormName(tabFormName As Control, Index As Integer)
As String

Dim ctl As Control
With tabFormName.Pages(Index)
For Each ctl In .Controls
If ctl.ControlType = acSubform Then
GetSubFormName = ctl.Name
End If
Next ctl
End With
End Function
I think you might want something like the following
[quoted text clipped - 35 lines]
 

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