Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a variable to call an unbound text box 1

Status
Not open for further replies.

bill420

IS-IT--Management
Oct 12, 2005
23
US
I have a set of unbound text boxes numbered 181 thru 205, I'm trying to fill with the following code.
Code:
cnt01 = 0
    cntBox = 181
    Do While cnt01 < cntRes
        Me.Text(cntBox).BackColor = lngRed
        Me.Text(cntBox).ForeColor = lngRed
        cntBox = cntBox + 1
        cnt01 = cnt01 + 1
    Loop
cntBox is declared as an integer.
This, of course, doesn't work.
How can this be done?
Bill
 
me.controls(controlName).[property] = someValue

--------------------
Procrastinate Now!
 
I have a set of unbound text boxes numbered 181 thru 205
Do you mean that their Names are 181, 182, 183, etc. ?

In that case, you could do something like this:
Code:
Private Sub cmdPopulate_Click()
    Dim x As Integer
    
    For x = 181 To 182
        Me.Controls(CStr(x)) = "data for " & x
    Next x
    
End Sub

Notice I put CStr around X to convert it to a string. Otherwise I would get an error message because Access would look for the 181th control, instead of the control named "181".

 
Hi...

This also works...

Dim StrCntl as String

For x = 181 to 205
StrCntl = "Text" & x
Me(StrCntl).BackColor = vbRed
Me(StrCntl).ForeColor = vbRed
next x
 
lewds,
Thanks for the fast reply.
Worked GREAT!!!
Thanks again for your insight.
Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top