Program a combobox/dropdownlist to create

  • Thread starter Thread starter ed
  • Start date Start date
E

ed

Hi all,

I want to Program a combobox/dropdownlist to create
textboxes dynamically.

A user simply selects a number from a combobox, say from 1-
10 and this creates a corresponding number of label and
textboxes.

Thanks
Edward


..
 
Where are these located?

Where do you want them created?

ActiveX controls or Forms controls?
 
Sorry, I left out pertinent information.

I want these controls created on a user form as form
controls.

Thanks
Ed
 
Instead of adding them, you could just design them in and hide them. Then after
you get the value from the user, just unhide the ones you want.

Option Explicit
Private Sub ComboBox1_Change()
Dim iCtr As Long
For iCtr = 1 To 10
Me.Controls("textbox" & iCtr).Visible _
= CBool(iCtr <= CLng(Me.ComboBox1.Value))
Next iCtr
End Sub
Private Sub UserForm_Initialize()
Dim iCtr As Long
For iCtr = 1 To 10
Me.Controls("textbox" & iCtr).Visible = False
Me.ComboBox1.AddItem iCtr
Next iCtr
End Sub

I put 10 textboxes in the userform. They were named textbox1 thru textbox10--so
the code would work.
 
Back
Top