|
-
Jun 10th, 2005, 04:36 PM
#1
Thread Starter
Member
Dynamically create Textboxes & Checkboxes in User Forms
I have created on user form. Within it is a dropdown that will prompt for a number. That integer saves to a variable which is public to the module.
I have created a second user form. Within that user form I would like to dynamically create a number of textboxes based on the integer to which the aforementioned dropdown saved its value. Is there a method to create textboxes on the fly within user forms, or how would I make this happen?
-
Jun 10th, 2005, 05:04 PM
#2
Frenzied Member
Re: Dynamically create Textboxes & Checkboxes in User Forms
You can create them dynamically, but have to set a lot of properties (top, left, etc), which could be a lot of work if the user has a lot of choices.
VB Code:
Dim t as textbox
t.top = 1600
t.name = "txtFoo"
'and so on
or, you could create the controls you want, set visible = false, and set visible = true based on whatever the value is.
Or, if the controls are the same but their values differ, just set those values when the form opens.
Last edited by salvelinus; Jun 10th, 2005 at 05:07 PM.
Tengo mas preguntas que contestas
-
Jun 13th, 2005, 12:50 PM
#3
Thread Starter
Member
Re: Dynamically create Textboxes & Checkboxes in User Forms
Do I have to set all of the properties, or just the ones like location that would be specific to the control? Would the rest take defaults? And from looking at your response, am I correct in figuring then that all I have to do is declare a variable of that type? There isn't an add method to tell it that variable goes into a specific user form? How do I associate this with a specific userform if I want to get an answer from a dropdown in one form, which would show the input userform upon clicking in the aforementioned dropdown?
-
Jun 13th, 2005, 01:10 PM
#4
Re: Dynamically create Textboxes & Checkboxes in User Forms
-
Jun 14th, 2005, 03:44 PM
#5
Thread Starter
Member
Re: Dynamically create Textboxes & Checkboxes in User Forms
I'm too much of a newbie at VBA to quite follow that one. I'm not sure where in my code I would be adding the text box and how I would be telling it to which user form the text box is being added.
For the time being, I think it will be more efficient for me to go with your first suggestion and simply make the text boxes all invisible then use an iterative structure to change them to visible until the number the dropdown supplied is reached. However, that brings more questions up for me.
I tried accessing the text boxes like so:
Code:
Dim BxName As String
Dim ChkName As String
Dim i As Integer
'Num is a global integer
For i = 1 To Num
BxName = "NameBox" & CStr(Num)
ChkName = "U18Chk" & CStr(Num)
KidPrompt.BxName.Visible = True
KidPrompt.ChkName.Visible = True
Next Num
But it doesn't let me replace the textbox name with a variable holding that name. How can I loop through the text & check boxes to make them visible so that it stops after the global Num value & only makes visible certain boxes (there are others that will be made visible if the checkbox is true)
-
Jul 15th, 2005, 01:19 AM
#6
New Member
Re: Dynamically create Textboxes & Checkboxes in User Forms
 Originally Posted by kfcSmitty
This will not work, there is no index in texbox property in VBA.
Kaaja
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|