Solved

Step through the sections in a report

Posted on 2011-02-22
4
436 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now