Controls in/outside a tab control on a form

J

Jess

I have a form with a tab control. This form also has additional controls
outside this tab control.

How can I know programmatically whether a given control on this form is in
the tab control or not? If a given a control is in the tab control, how can I
know programmatically which page this control belongs to?
 
J

Jack Leach

I'm not sure this is possible. Programatically, it doesn't matter if the
control is on a tab or not... everything is referred to as if the tab control
doesn't exist. You may want to implement a naming scheme or a tag value to
these controls as a way to help you with that.

--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
J

JimBurke via AccessMonster.com

I like Jack's idea of using the tag control. As an alternative, I think you
could do it by creating a function something like this:

Private Function ControlBelongsToTab(byref tabCtl as tabControl, byval
ctlName as string) As Boolean

dim tempField as variant

on error goto NotOnTab
tempField = tabCtl.Controls(ctlName).value
ControlBelongsToTab = True
Exit Function

NotOnTab:
ControlBelongsToTab = False

End Function

This would try to assign the value of the control that might be on the tab to
a variant variable. My premise is that if that control is on that tab, the
assignment statement will work and execution will continue to the next
statement after the assignment statement, and if it's not an error will be
generated and execution will go to the lebelled statement specified in the On
Error. To call the function you would pass the tab control itslef and the
name of the control you are checking, e.g. if the tab is called tabA and the
control is called txtA you would use

If ControlBelongsToTab(tabA, txtA.Name) Then...

In theory this seems like it should would work but I haven't tested it.
 
J

JimBurke via AccessMonster.com

Whoops, I meant tag property, not tag control.
I like Jack's idea of using the tag control. As an alternative, I think you
could do it by creating a function something like this:

Private Function ControlBelongsToTab(byref tabCtl as tabControl, byval
ctlName as string) As Boolean

dim tempField as variant

on error goto NotOnTab
tempField = tabCtl.Controls(ctlName).value
ControlBelongsToTab = True
Exit Function

NotOnTab:
ControlBelongsToTab = False

End Function

This would try to assign the value of the control that might be on the tab to
a variant variable. My premise is that if that control is on that tab, the
assignment statement will work and execution will continue to the next
statement after the assignment statement, and if it's not an error will be
generated and execution will go to the lebelled statement specified in the On
Error. To call the function you would pass the tab control itslef and the
name of the control you are checking, e.g. if the tab is called tabA and the
control is called txtA you would use

If ControlBelongsToTab(tabA, txtA.Name) Then...

In theory this seems like it should would work but I haven't tested it.
 
D

Dale Fye

The controls parent.Name property will indicate either a the tab control page
name or the form name (at least it does in 2007).

?forms(Formname).ControlName.parent.name

I give all of may tab controls names that start with tab, and all of my
forms names that start with frm.
 
K

Krzysztof Naworyta

Jess wrote:
| I have a form with a tab control. This form also has additional
| controls outside this tab control.
|
| How can I know programmatically whether a given control on this form
| is in the tab control or not? If a given a control is in the tab
| control, how can I know programmatically which page this control
| belongs to?


Private Sub Command1_Click()

Dim ctr As Control
Dim ob As Object

For Each ctr In Me.Controls
Select Case ctr.ControlType
Case acPage, acTabCtl
Case Else
Set ob = ctr
Do
Set ob = ob.Parent
If TypeOf ob Is Page Then

Debug.Print ctr.Name, "page:" & ob.Name, ob.Caption
Debug.Print ,"index:", ob.PageIndex, "tab:", ob.Parent.Name
GoTo lab1:
End If
Loop Until TypeOf ob Is Form
Debug.Print ctr.Name, "OnForm"
End Select
lab1:
Next


End Sub
 

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