3
Contributors
4
Replies
6
Views
8 Years
Discussion Span
Last Post by abu taher
0

Hi,
Please find the code below to create VB Controls/Array of Controls Dynamically

Dim ControlArrayCOunt As Integer
Dim txtControlArray() As TextBox
Private Sub Create_Control()
On Error GoTo a

Dim txtControl As TextBox
Set txtControl = Controls.Add("VB.TextBox", "txtControl")
txtControl.Top = 300
txtControl.Left = 200
txtControl.Visible = True
Exit Sub

a:


End Sub

Private Sub Create_ControlArray()
On Error GoTo a

ReDim txtControlArray(ControlArrayCOunt)

Set txtControlArray(ControlArrayCOunt - 1) = Controls.Add("VB.TextBox", "txtControl" & ControlArrayCOunt)
txtControlArray(ControlArrayCOunt - 1).Text = "TextBox" & ControlArrayCOunt
txtControlArray(ControlArrayCOunt - 1).Top = 300 + (ControlArrayCOunt * 400)
txtControlArray(ControlArrayCOunt - 1).Left = 300
txtControlArray(ControlArrayCOunt - 1).Visible = True
Exit Sub

a:
End Sub
'Command Button to create Control Once Dynamically
Private Sub Command1_Click()
Call Create_Control
End Sub
'Command Button to create Control array Dynamically
Private Sub Command2_Click()
ControlArrayCOunt = ControlArrayCOunt + 1
Call Create_ControlArray
End Sub

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.