Solved

Step through the sections in a report

Posted on 2011-02-22
4
441 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
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…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

749 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