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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

addressing a userform textbox via a loop

Status
Not open for further replies.

scottscott

Programmer
Dec 14, 2006
29
0
0
US
Is it possible to access a userform textbox through a for loop?

for i = 1 to 9

if myform.textbox1.value = 1 then
'perform task
end if
next i

Is there anyway to replace myform.textbox1.value with myform.textbox(i).value?
 
Sure !

You have to know the ordinal positions though. Generally, you want to create 9 in a row to insure their ordinal positions are sequential.

Or, you can use the tag property and the typeofcontrol property to loop through and check to see if it's a check box.

I've used a routine similiar to this to clear all the text boxes in a form, or you can fill stuff in like this:

Code:
Private Sub Command12_Click()
Dim ctl As Control
For i = 0 To Me.Controls.Count - 1
     
     Set ctl = Me.Controls(i)
        If ctl.ControlType = acTextBox Then
            Me.Controls(i).SetFocus
            Me.Controls(i).Value = i + 1
        End If
        
Next i
End Sub



Tyrone Lumley
SoCalAccessPro
 
Is it possible to access a userform textbox through a for loop?

Yes.

Is there anyway to replace myform.textbox1.value with myform.textbox(i).value?

Yes, sort of. You need to create a control object, then set that object to what you need it to be.

Something like:

dim mybox as control

function namebox(number as integer)
namebox = "textbox"&number
end

set mybox = namebox(1)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top