ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   accesing controls in for each loop (https://www.excelbanter.com/excel-programming/330045-accesing-controls-each-loop.html)

Gixxer_J_97[_2_]

accesing controls in for each loop
 
hi all!

when you are using something like:

for each o in multipage1.pages(0).controls

next

o is the current control being 'looked' at out of the X number of controls
on multipage1.pages(0)

my question is - how do you access the previous control? ie so you could
compare the contents of the previous text box with the present text box.

tia!

J

Greg Wilson

accesing controls in for each loop
 
I suggest you don't use a For Each loop but a For i = x to y type instead:

Dim i As Integer
With MultiPage1.Pages(0)
'Index value of 1st control is 0 and last control is .Controls.Count - 1
For i = 1 To .Controls.Count - 1
MsgBox .Controls(i).Text & vbCr & .Controls(i - 1).Text
Next
'Alternate:
'For i = 2 To .Controls.Count
'MsgBox .Controls("TextBox" & i).Text & vbCr & .Controls("TextBox" & i -
1).Text
'Next
End With

Regards,
Greg Wilson

"Gixxer_J_97" wrote:

hi all!

when you are using something like:

for each o in multipage1.pages(0).controls

next

o is the current control being 'looked' at out of the X number of controls
on multipage1.pages(0)

my question is - how do you access the previous control? ie so you could
compare the contents of the previous text box with the present text box.

tia!

J



All times are GMT +1. The time now is 12:28 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com