Count Property Example

The following example displays the Count property of the Controls collection for the form, and the Count property identifying the number of pages and tabs of each MultiPage and TabStrip.

To use this example, copy this sample code to the Declarations portion of a form. The form can contain any number of controls, with the following restrictions:

Note   You can add pages to a MultiPage or add tabs to a TabStrip. In Windows, double-click the control, then right-click in the tab area of the control and choose New Page from the shortcut menu.

Private Sub UserForm_Initialize()
    Dim MyControl As Control

    MsgBox "UserForm1.Controls.Count = " _
        & Controls.Count

    For Each MyControl In Controls
        If (MyControl.Name Like "MultiPage*") Then
            MsgBox MyControl.Name _
                    & ".Pages.Count = " _
                    & MyControl.Pages.Count
        ElseIf (MyControl.Name Like "TabStrip*") Then
            MsgBox MyControl.Name & ".Tabs.Count = " _
                    & MyControl.Tabs.Count
        End If
    Next

End Sub