vba newbie question

V

vbaNOOB

Hi all,

I want to create a vba program that allow user to input a num(eg 3)
Then the program will add 3 textbox in the form

The problem is how I can get the value of these textbox?
The easiest way to do that is I create couple of textbox in the form, and
hide them
When the user enter 3, I just show the first 3 textbox. Also, I can get the
text from the textbox, becoz the textbox exist.

Is there a better way to do it??
For other language, I can run a string as a line of code. As I know, vba
can't....

Dim i as integer
for i = 1 to num ( from user)
textbox & "i".text = "hihi" <---- I know I cant do it @@
next

Sorry for my bad English. I hope u guys understand what I'm saying
Thanks
 
H

Helmut Weber

Hi,

one way:

Private Sub CommandButton1_Click()
Dim l As Long
For l = 1 To 3
Me.Controls("textbox" & CStr(i)).Text = CStr(i)
Next
End Sub

Another way is to google in the groups for

array controls

and my decent name,

on how to create an array of controls at runtime.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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