Textbox control

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello, I'm creating a quote template through userforms. I have one section to
where the user will have to enter a customer number and city/state for up to
10 listings. So the user will enter a number (1 through 10) and the
appropriate number of boxes will appear. So if they enter 8, the first 8
boxes will appear. If they change their selection to 5, then only the first 5
boxes will appear. Now I know I can program a bunch of if statements to
control the boxes but that would be a lot ifs, is there a more simple way of
doing this via a loop or something? Any help and guidance is appreciated.
Thanks.
 
Brad, Are you looking to do something like this?
Dim cnt As Long
Dim tb As MSForms.TextBox
For cnt = 0 To 9
Set tb = UserForm1.Controls.Add("Forms.TextBox.1", "Textbox" & cnt +
1)
tb.Top = tb.Height * cnt + 5
Next
 
Very close.

The textboxes are already there, but based on the # entered, it will
determine how many of those boxes will be visible. So the loop or 'next'
statement will force the textbox to be visible (textbox2.visible = true).

Thank you for help!
 
Brad, Try this:
Dim TB as MSForms.TextBox
Dim cnt as Long
For cnt = 0 to 9
Set TB = UserForm1.Controls("TextBox" & cnt + 1)
TB.Visible = True 'Add logic here
Next

P.S. This is untested but should get you very close. Let me know if you need
help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top