How to: Add a Control to a MultiPage Control
The following example uses the Add, Clear, and Remove methods of the Microsoft Forms 2.0 Controls collection to add a control to and remove a control from a Page of a MultiPage at run time.
To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:
A MultiPage named MultiPage1.
Three CommandButton controls named CommandButton1 through CommandButton3.
Dim MyTextBox
Dim MultiPage1
Sub Item_Open()
Set MyPage = Item.GetInspector.ModifiedFormPages("P.2")
Set MultiPage1 = MyPage.MultiPage1
MyPage.CommandButton1.Caption = "Add control"
MyPage.CommandButton2.Caption = "Clear controls"
MyPage.CommandButton3.Caption = "Remove control"
End Sub
Sub CommandButton1_Click()
Set MyTextBox = MultiPage1.Pages(0).Controls.Add("Forms.TextBox.1", "MyTextBox", 1)
End Sub
Sub CommandButton2_Click()
MultiPage1.Pages(0).Controls.Clear
End Sub
Sub CommandButton3_Click()
If MultiPage1.Pages(0).Controls.Count > 0 Then
MultiPage1.Pages(0).Controls.Remove "MyTextBox"
End If
End Sub