Set Visible property of various sections in a report thru VBA

G

Guest

How can I set the visible property of all the sections in a report in VBA.

I am trying to set the visible property of certain sections in a report to
false if it meets a certain criteria and true if it does not.

Any help would be appreciated

Thanks
 
M

Marshall Barton

Kpatel said:
How can I set the visible property of all the sections in a report in VBA.

I am trying to set the visible property of certain sections in a report to
false if it meets a certain criteria and true if it does not.


Do it the same way you set the visibility of anything else
using VBA.

Me.<section name>.Visible = False
or
Me.Section(<sectionNumber>).Visible = False
 
G

Guest

I am aware of this. However, what I was looking for is how can I create a
loop that goes through every section on the report and sets the visibility
property. Something similar to this

Dim ctl as Controls
For Each ctl In Me.Controls
ctl.Visible = False
Next

But I want to be able to do this for every section on the report. Also, I
would like to know what event should I be doing this in.

Thanks
 
G

Guest

WHY would you want to loop through every control in a section, when you can
issue a single command and affect the entire section?
 
G

Guest

I am not looping through every control in a section, that was just an example
of what I intended to get to with this request for help. I have several
reports and all of them have varying amount of sections in them. My
intention is to create a summary report or an option report from a single
report and the user being given the choice as to what kind of report they
would like. When they choose the summary report, for example, I would like
to set the visible property of all the sections that have a Tag property set
to "Detail Report" to false.

Any suggestions on how I could do this in a "simple" code?

Thanks for any help that can be provided.
 
M

Marshall Barton

Kpatel said:
I am aware of this. However, what I was looking for is how can I create a
loop that goes through every section on the report and sets the visibility
property. Something similar to this

Dim ctl as Controls
For Each ctl In Me.Controls
ctl.Visible = False
Next

But I want to be able to do this for every section on the report. Also, I
would like to know what event should I be doing this in.


There is no Sections collection so that kind of thing is not
doable.

Each control in a form/report has a Section property that
tells you which section contains the control. I guess you
could loop through the Controls collection and construct an
array or collection of the section numbers in the
form/report, However, by the time you do all that, you
could just set each section's Visible property with less
code.

The only alternative I can think of is a loop like:

On Error GoTo AllDone
For N = 0 To 23
Me.Section(N).Visible = False
Next N
AllDone:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top