Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

How to control number of textboxes according to user input

  Asked By: Hisham    Date: Sep 23    Category: MS Office    Views: 758
  

I have a Userform with a list box. The user can select
a value from 4 to 10 from this list box. Depending on
this response i have to display number of text boxes
where the use can enter values. In case the user
selects the value 4 from the list box, I have to
display 4 text boxes so that he can enter 4 values.

How do i do this??

Share: 

 

4 Answers Found

 
Answer #1    Answered By: Cecelia Sims     Answered On: Sep 23

You should put 10 text  boxes on your form. Hook into the change event on
your list  box and make boxes  5-10 visible/invisible based on the listbox
selection.

 
Answer #2    Answered By: Elliot Evans     Answered On: Sep 23

you know the
number will be between 4 and 10. In a case  where you do not know what
the number  will be, or if you need to be more flexible about the things
you want to change about your userform  based on conditions at runtime,
you can learn how to modify your userform by adding or removing controls
at runtime in my article "Dynamic UserForms" in the December 2003 issue
of TechTrax -- see
pubs.logicalexpressions.com/.../LPMArticle.asp

 
Answer #3    Answered By: Bes Massri     Answered On: Sep 23

I think later in
another case  i have to acccomodate upto 20, maybe then
i will use your suggestion.

 
Answer #4    Answered By: Naba Malik     Answered On: Sep 23

I was trying to add textboxes  or lables as a dynamic array. I would like to use
this data to run a excel statistics function. The code i ended up with was

'NoStdInput is the name of my listbox
Private Sub NoStdInput_Click()
Dim NoOfStds As Integer

'This is for a dynamic array of labels, was planning to do the same for
textboxes
Dim ArrayOfLbl() As Label

'Counter for the for loop
Dim I As Integer

NoOfStds = NoStdInput.Value

For I = 1 To NoOfStds

'This is for dynamiccally definign my array of lables
ReDim Preserve ArrayOfLbl(1 To I)

'To add a new label & this is where a run-time error occurs , UserForm1 is
the name of the UserForm.
Set ArrayOfLbl(I) = UserForm1.Controls.Add("Forms.Label.1","nameoflabel",
"true")

'This is to position each label
With ArrayOfLbl(I)
.Left = 10 * I
.Top = 100
.Width = 30
.Caption = "Enter your name:"
End With

Next

End Sub


Is it a good idea to add objects as a dynamic array? what could be the problem
with this code???

 
Didn't find what you were looking for? Find more on How to control number of textboxes according to user input Or get search suggestion and latest updates.




Tagged: