Editing a specific textbox depending on a number

adamk

New member
Local time
Today, 10:58
Joined
Oct 24, 2012
Messages
5
Hi,

Essentially I want to edit a specific textbox depending on a number which is dependent on a number of things and varies each time the form is run.

For example, if the number is 0 I want to edit tb0.value. If it's 1 I want to edit tb1.value etc. I have specifically labelled my text boxes in this way.


I thought something like this would work

textBoxName = "tb" & number
textBoxName.value = "this is the value I want to enter".

However, this does not work and it produces an error saying 'Invalid Qualifier'.

Please help.

Thanks :)
 
Referring to form controls based on variable names is quiet different.. You normally use.. Forms.Control("<<controlName>>").. So in your case it will be..
Code:
Dim textBoxName As String
textBoxName = tb & Me.someNumberField

Forms.Controls(textBoxName) = "Some Value"
 
Thanks for the reply.

I have tried that, and it is still not working. Here is the code I wrote.

---------------------------
Dim numberOfTextBoxes As Integer
Dim textBoxName As String

numberOfTextBoxes = 20

For i = 1 To numberOfTextBoxes

textBoxName = "tb" & Me.i
Forms.Controls(textBoxName) = ""

Next
------------------------------
 
For those interested.

Got the answer

Dim numberOfTextBoxes As Integer
Dim textBoxName As String
Dim i As Integer


numberOfTextBoxes = 20


For i = 1 To numberOfTextBoxes
Me("tb" & i) = ""
Me("tb" & i).BackColor = vbWhite
Next
 

Users who are viewing this thread

Back
Top Bottom