Remove Method

Applies To

Controls collection, Pages collection, Tabs collection.

Description

Removes a member from a collection; or, removes a control from a Frame, Page, or form.

Syntax

object.Remove( collectionindex)

The Remove method syntax has these parts:

Part

Description

object

Required. A valid object.

collectionindex

Required. A member's position, or index, within a collection. Numeric as well as string values are acceptable. If the value is a number, the minimum value is zero, and the maximum value is one less than the number of members in the collection. If the value is a string, it must correspond to a valid member name.


Remarks

This method deletes any control that was added at run time. However, attempting to delete a control that was added at design time will result in an error.

See Also

Add method, Clear method.

Example

The following example uses the Add, Clear, and Remove methods to add and remove a control to a Page of a MultiPage at run time.

To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains:

  • A MultiPage named MultiPage1.
  • Three CommandButton controls named CommandButton1 through CommandButton3.
    Dim MyTextBox As Control
    
    Private Sub CommandButton1_Click()
    Set MyTextBox = MultiPage1.Pages(0).Controls.Add("Forms.TextBox.1", _
    "MyTextBox", Visible) End Sub Private Sub CommandButton2_Click() MultiPage1.Pages(0).Controls.Clear End Sub Private Sub CommandButton3_Click() If MultiPage1.Pages(0).Controls.Count > 0 Then MultiPage1.Pages(0).Controls.Remove "MyTextBox" End If End Sub Private Sub UserForm_Initialize() CommandButton1.Caption = "Add control" CommandButton2.Caption = "Clear controls" CommandButton3.Caption = "Remove control" End Sub