Text Box number as a variable
Hello All,
Is it possible to have a For/Next loop for Text Box numbers?
I tried the following code but I get a error message:
"Object variable or with block variable not set".
Code:
Private Sub Form_Load()
Dim a As Integer
Dim texta As TextBox
For a = 1 To 2
texta.text = 2
texta.text = 4
Next a
End Sub
Any ideas.
Regards
Tarablue
Re: Text Box number as a variable
You can use Controls collection:
Code:
For a = 1 To 2
Me.Controls("Text" & a).Text = 2
Next a
You may also need to add some validations but this should get going at least.
Re: Text Box number as a variable
Hello RhinoBull,
Thank you for that. I just realised that my coding should be attached to a Command Button and NOT in the Private Sub Form_Load() area, but the error I got was the same. Your code seems to work OK so I'll try it in my main program and see how I get on.
Regards
Tarablue