Solved

Step through the sections in a report

Posted on 2011-02-22
4
440 Views
Last Modified: 2013-11-28
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


0
Comment
Question by:Fritz Paul
  • 2
4 Comments
 
LVL 77

Accepted Solution

by:
peter57r earned 250 total points
ID: 34950439
Sub rptsec()

On Error GoTo endofsections
Dim x As Long
Dim rpt As Report
Set rpt = Reports!rptProfiles

For x = 0 To 100
Debug.Print rpt.Section(x).Name, rpt.Section(x).[Height]
Next x
endofsections:
' exit on error because you can't tell in advance how many sections there are

End Sub

0
 
LVL 9

Expert Comment

by:borki
ID: 34950513
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
0
 

Author Closing Comment

by:Fritz Paul
ID: 34950620
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.
0
 
LVL 77

Expert Comment

by:peter57r
ID: 34950755
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.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question