2
votes

I have a userform with a runtime-defined multipage. On launch, the multipage populates a number of pages, each with their own textbox.

Example of the multipage defined during runtime.

The challenge comes that during runtime, the user can reorder, delete, add and rename these pages. At the end, I need to call all data from each page of the multipage, including the textbox. This means that within Me.Controls, the item numbers are not useful as they become jumbled.

However, within each page of the multipage is a further set of controls, which will only ever have the 1 item (the textbox). This means when I sweep the multipage in a 'for' loop, I could just always call item 1, similar to a 'me' statement.

Item1 within controls of each page of the multipage object.

However the code fails when I try to go beyond the second bunch of controls to call the value of the textbox.

For i = 0 to Last_Page-1
Example_String = Me.My_MultiPage.Pages.Item(i).Controls.Item(1).Value
Next i

Why can I not call this second tier of controls? Without this i have to write a huge amount of work-around code to manage names of each textbox as the user re-orders them.

Thanks in advance!

1

1 Answers

0
votes

Collections use a 0 based index.

For i = 0 to Last_Page-1
    Example_String = Me.My_MultiPage.Pages.Item(i).Controls.Item(0).Value
Next i

.Item is not needed because a Collection's default value is its Items.

For i = 0 to Last_Page-1
    Example_String = Me.My_MultiPage.Pages(i).Controls(0).Value
Next i