Userform Order Of Controls When Running For

  • Hi all,

    What determines the order of controls when running the for command through a userforms controls?

    ie if I have the code below:

    For Each ctl In PageViewer.Controls
            If TypeOf ctl Is MSForms.CheckBox Then            
                MsgBox ctl.Name
            End If

    The first msgbox i get is "Checkbox12"
    the next is "Checkbox1" etc They are not in order.


  • Re: Userform Order Of Controls When Running For

    Hi andy,

    I was using this peice of code:

    And because the checkboxes, I have about 12 of them, where out of order it was'nt working probably. I looked at you answer and deleted the ones that were out of place and then readded them. It worked.


  • Re: Userform Order Of Controls When Running For

    Well the first part of the code sets all the command buttons to an array which were all in order.

    The second part cycles through the checkboxes and sets the checkbox value to the sheets visibility property, and then sets the commandbutton enabled property to the checkbox value.

    But the check boxes werent in order so on the first cycle of the FOR (which happened to be checkbox 12) it was being set to sheet 2 when it should have been set to sheet 13, and it was also setting command button 2, when commandbutton 2 should have been set by checkbox1.

    I dont know why the for command was starting at checkbox12 and then going to checkbox1 and onwards. But andys suggestion fixed it.

    Make Sense? Please tell me if I'am missing something, I dont think the code is very good method but it seems to work, and is better than setting them all individually right?

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!