Link to home
Start Free TrialLog in
Avatar of Fritz Paul
Fritz PaulFlag for South Africa

asked on

Step through the sections in a report

I want to address each section in a report with VBA, which is already open in design mode.
I specifically want to use the For Each code.

What I've got now is

     Dim scn As Section
     For Each scn In [Reports]![rptProfiles1]    ' "rptProfiles1" is the report name
         Debug.Print Reports!rptProfiles1.Section(scn).[Name], Reports!rptProfiles1.Section(scn).[Height]
     Next

I just cannot get this section one to work.

However, what is working for the same report is

    Dim ctl As Control
    For Each ctl In Reports!rptProfiles1
                  Debug.Print ctl.Name, ctl.Height
    Next

Please help with the section code


ASKER CERTIFIED SOLUTION
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Section is not a collection object but a fixed array. You must determine the max number of valid section objects at design time.

You can then address the a single object using an integer or a predefined constant such as acDetail (0).

HTH
Avatar of Fritz Paul

ASKER

Thanks.
I wanted to specifically use

For Each section in report
......
Next

Because I can not get it to work,

But the solution given is neat and easy.
As borki said, to be able to use ' for each section in...' there has to be a Sections collection object.  But there is no such collection so you have to use the section array.