Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Step through the sections in a report

Posted on 2011-02-22
4
Medium Priority
?
446 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 1000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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 …

618 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