How to list all controls in a page of a tab control.

T

ThomasAJ

How is this done and how do I obtain the name and type of the control.
By type I mean say label or text etc.
 
M

Marshall Barton

ThomasAJ said:
How is this done and how do I obtain the name and type of the control.
By type I mean say label or text etc.


For Each ctl In Me.tabcontrol.Pages(N).Controls
Debug.Print ctl.Name, ctl.ControlType
Next ctl

The currently display page number of a tab control is the
value of the table control. I.e.
Me.tabcontrol.Pages(Me.tabcontrol).Controls

Note that the type is a integer. You would have to create a
function to convert the number to text. See ControlType in
Help for details.
 
J

John Vinson

How is this done and how do I obtain the name and type of the control.
By type I mean say label or text etc.

Tools... Analyze... Documentor will do it; or you can loop through the
Form's Controls collection. There are VBA constants for each control
type - they're not terribly intuitive though! You may need to use an
expression like

Dim iType As Integer
Dim sType As String
Dim ctl As Control
For Each ctl In Me.Controls
iType = ctl.Properties("ControlType")
sType = Switch(iType = acTextbox, "Textbox", _
iType = acLabel, "Label", _
iType = acCheckbox, "Checkbox", _
<and so on>
Debug.Print ctl.Name, sType
Next ctl



John W. Vinson[MVP]
 
Top