filling fields

skate

Registered User.
Local time
Today, 16:09
Joined
May 22, 2002
Messages
136
i have an array(9) and want to fill corresponding txtboxes so that array(0) fills txtbox0, array(1) fills txtbox1, array(2) fills txtbox2. is there a way to do this with a loop?
 
Code:
Private Sub cmdPutinBoxes_Click()

'form name = frmArrays

'Textbox names on the form are as follows
'txtName0
'txtName1
'txtName2
'etc

Dim SomeNumbers(8) As Integer 'an array that holds up to nine integers
Dim i As Integer 'a variable that holds an integer
Dim TextBoxName As Object

'Note: define the loop and go
For i = 0 To 8 'do whatever follows nine times
'Note: the value of i is 0 on the first pass
'Note: the value of i is 1 on the second pass
'Note: the value of i is 2 on the third pass, etc

Set TextBoxName = Forms("frmArrays")("txtName" & i)
' this will read Forms("frmArrays")("txtName0") on the first pass, 
' this will read Forms("frmArrays")("txtName1") on the 2nd pass, etc

'assign value to array for this code sample
SomeNumbers(i) = i

TextBoxName = SomeNumbers(i)
'Translation: me.txtName0 = SomeNumbers(0) =  on first pass of loop.
'me.txtName1 = SomeNumbers(1) = on 2nd pass of loop, etc

Next i 'Note: go back if not done

'otherwise, leave
End Sub
Regards,
Tim
 

Users who are viewing this thread

Back
Top Bottom