Create Multiple textboxes on-the-fly

T

Tyler Farmer

To make a long story short, I want to be able for a user to input a number
(say 1-10), click the "go" button, and have the form dynamically create a
bunch of new text boxes (based on the number the user input). I know in
regular VB I can create a control array, but in Access you can't...but can
you just create new text boxes, and then give them names like "txt1",
"txt2", "txt3", etc.?

Then is there an easy way to reference them with loops later on?
 
M

Marshall Barton

Tyler said:
To make a long story short, I want to be able for a user to input a number
(say 1-10), click the "go" button, and have the form dynamically create a
bunch of new text boxes (based on the number the user input). I know in
regular VB I can create a control array, but in Access you can't...but can
you just create new text boxes, and then give them names like "txt1",
"txt2", "txt3", etc.?

Then is there an easy way to reference them with loops later on?


You do not want to use CreateControl at run time (it's a
design time wizard type of funvtion). Instead, precreate a
bunch of invisible text boxes and then, in response to the
user's action, make them visible as needed.

If the precreated text boxes are named as you suggested,
then you can refer to them with this kind of syntax:

Me("txt" & k).Visible = True
 
T

TC

(snip)
You do not want to use CreateControl at run time (it's a
design time wizard type of funvtion). Instead,


Years ago, I tried to write a PERT chart scheduling form in Access. The user
needed to be able to click & drag, to draw a new box on the screen, to
represent a new schedule task. To create new boxes at runtime, I even tried
having the form close itself (which of course, does not actually stop the
rest of the code from executing), then re-open itself in design mode! The
reopen does work (!), but the createcontrol still dies, sadly...

TC
 
D

Dale Fye

What are you going to do with the values that get stored in these
textboxes?

How about using a subform? You could have some sort of a details
table that when they enter the number, your code would insert a
separate record in the details table for each number, and obviously
another field that indicates the project or the user, or something
along those lines.

Then, you requery the subform and it will display however many
textboxes you want. The advantage of the subform, is that if they
enter 20, you will have a vertical scroll bar to move between the
textboxes.

--
HTH

Dale Fye


To make a long story short, I want to be able for a user to input a
number
(say 1-10), click the "go" button, and have the form dynamically
create a
bunch of new text boxes (based on the number the user input). I know
in
regular VB I can create a control array, but in Access you can't...but
can
you just create new text boxes, and then give them names like "txt1",
"txt2", "txt3", etc.?

Then is there an easy way to reference them with loops later on?
 

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

Top