Answered by:
Concat textbox name with string

Question
-
Hi,
greetings for all access experts in this forum
I got problems when trying to concat between my text box name with string.
In my form there are 10 textboxs named : Student1, Student2, Student3... Student10
I tried to get value from each textbox
This is my code :
It's not working. No error also.Dim a as string
a = 1
do until a = 2
MsgBox (Me.Controls("Student"&a).Value)
loop
Any help would be appreciated.
Many thanks.Saturday, June 8, 2013 12:33 PM
Answers
-
Hi,
greetings for all access experts in this forum
I got problems when trying to concat between my text box name with string.
In my form there are 10 textboxs named : Student1, Student2, Student3... Student10
I tried to get value from each textbox
This is my code :
It's not working. No error also.Dim a as string
a = 1
do until a = 2
MsgBox (Me.Controls("Student"&a).Value)
loop
Any help would be appreciated.
Many thanks.
Hi Dwif,
First, declare a as Integer
If you use Do Until, then you have to increment the counter in the loop by yourself. For instance:
Dim a As Integer
a = 1
Do Until a = 2
MsgBox Me("Student" & a)
a = a + 1
LoopAnother (easier) way is:
Dim a As Integer
For a = 1 To 10
MsgBox Me("Student" & a)
Next 'LoopImb.
- Proposed as answer by Douglas J Steele, MVP Saturday, June 8, 2013 1:21 PM
- Edited by Imb-hb Saturday, June 8, 2013 1:33 PM Next in a For statement
- Marked as answer by Dwif Sunday, June 9, 2013 12:48 AM
Saturday, June 8, 2013 1:18 PM
All replies
-
Hi,
greetings for all access experts in this forum
I got problems when trying to concat between my text box name with string.
In my form there are 10 textboxs named : Student1, Student2, Student3... Student10
I tried to get value from each textbox
This is my code :
It's not working. No error also.Dim a as string
a = 1
do until a = 2
MsgBox (Me.Controls("Student"&a).Value)
loop
Any help would be appreciated.
Many thanks.
Hi Dwif,
First, declare a as Integer
If you use Do Until, then you have to increment the counter in the loop by yourself. For instance:
Dim a As Integer
a = 1
Do Until a = 2
MsgBox Me("Student" & a)
a = a + 1
LoopAnother (easier) way is:
Dim a As Integer
For a = 1 To 10
MsgBox Me("Student" & a)
Next 'LoopImb.
- Proposed as answer by Douglas J Steele, MVP Saturday, June 8, 2013 1:21 PM
- Edited by Imb-hb Saturday, June 8, 2013 1:33 PM Next in a For statement
- Marked as answer by Dwif Sunday, June 9, 2013 12:48 AM
Saturday, June 8, 2013 1:18 PM -
You should have 10 records rather than 10 textboxes!
Build a little, test a little
Saturday, June 8, 2013 3:21 PM -
You should have 10 records rather than 10 textboxes!
Build a little, test a little
Hi Karl,
Not necessarily. For instance to make a floor plan of a student class, using an unbound form.
Imb.
Saturday, June 8, 2013 4:43 PM -
It's works!
Many thanks Imb :)
Sunday, June 9, 2013 12:50 AM