Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

looping through Excel controls

DriestDriest Posts: 6Member
I have a custom excel form and a list of checkboxes inside the form. When checked, it will print a particular table on one page. I also have a button to print the entire booklet at once. This will cycle through all controls and check them if they are a checkbox. The problem is it seems to do so in a random manner. The code for the buttonn pressed is as follows:

Private Sub cmdBooklet_Click()
Dim pPage As Page
Dim cCont As Control

For Each pPage In MultiPage1.Pages
For Each cCont In pPage.Controls
If TypeName(cCont) = "CheckBox" Then
cCont.Value = True
End If
Next cCont
Next pPage

End Sub

Is there a way i can loop through the controls in a particular order? The tab order doesn't seem to do much.

Thanks for your help

Comments

  • PavlinIIPavlinII Posts: 404Member
    : I have a custom excel form and a list of checkboxes inside the form. When checked, it will print a particular table on one page. I also have a button to print the entire booklet at once. This will cycle through all controls and check them if they are a checkbox. The problem is it seems to do so in a random manner. The code for the buttonn pressed is as follows:
    :
    : Private Sub cmdBooklet_Click()
    : Dim pPage As Page
    : Dim cCont As Control
    :
    : For Each pPage In MultiPage1.Pages
    : For Each cCont In pPage.Controls
    : If TypeName(cCont) = "CheckBox" Then
    : cCont.Value = True
    : End If
    : Next cCont
    : Next pPage
    :
    : End Sub
    :
    : Is there a way i can loop through the controls in a particular order? The tab order doesn't seem to do much.
    :
    : Thanks for your help
    :
    Hi,
    you can try to
    [code]
    Dim pi as integer, ci as integer
    For pi=1 to Multipage1.Pages.Count
    pPage=Multipage1.Pages(pi)
    For ci=1 to pPage.Controls.Count
    cCont=pPage.Controls(ci)
    [green]' ... some code ... [/green]
    Next ci
    Next pi
    [/code]This should keep the order of controls in pPage.Controls collection. But I think that For Each cycle will make the same order..
    If you want to set this order, you can remove controls from pPage.Controls collection and return them back in order you need..
    ..or try to iterate the collection once and store checkboxes in desired order in your own list..

    Hope this helps

    [blue][b][italic][size=4]P[/size]avlin [size=4]II[/italic][/size][/b][/blue]

    [purple]Don't take life too seriously anyway you won't escape alive from it![/purple]


Sign In or Register to comment.