You can dynamically add controls to a form or other container (such as a UserControl) using the Add
method of the container's Controls
collection. For example, to add a TextBox named myTextBox
to a form called frmMyForm, you could do this:
frmMyForm.Controls.Add "VB.TextBox", "myTextBox"
Here is a snippet from the VB6 help file:
Add Method (Controls Collection)
Adds a control to the Controls
collection and returns a reference to
the control.
Syntax
object.Add (***ProgID, name, container*)**
The Add method syntax has these parts:
object (Required)
An object expression that evaluates to
an object in the Applies To list.
ProgID (Required)
A string that
identifies the control. The ProgID of
most controls can be determined by
viewing the Object Browser. The ProgID
is composed of the Library and Class
of the control. For example, the
CommandButton control's ProgID is
VB.CommandButton. In cases where the
ProgID differs from that shown in the
Object Browser, Visual Basic displays
an error message that contains the
correct ProgId.
name (Required)
A string that identifies the member of
the collection.
container (Optional)
An object reference that specifies a
container of the control. If not
specified or NULL, defaults to the
container to which the Controls
collection belongs. You can put a
control in any existing container
control (such as the Frame control) by
specifying this argument. A user
control or an ActiveX document can
also be a container.