Hide a section based on contents at run-time

M

Mona-ABE

I have a report with 2 group headers and one detail section:
MODULE
BUSINESS
DETAIL

I always have module info, sometimes business info is empty, but the detail
section always has data for both. I'd like to supress the business header
and the corresponding detail section data when the business group header is
empty. Can you recommend the best way to do this either with VBA in the
report's onformat or onprint event, or some other way?
 
F

freakazeud

Hi,
use the group headers on format event with:

Cancel = Not Me.HasData

HTH
Good luck
 
M

Marshall Barton

Mona-ABE said:
I have a report with 2 group headers and one detail section:
MODULE
BUSINESS
DETAIL

I always have module info, sometimes business info is empty, but the detail
section always has data for both. I'd like to supress the business header
and the corresponding detail section data when the business group header is
empty. Can you recommend the best way to do this either with VBA in the
report's onformat or onprint event, or some other way?


How can you tell if the group header has no data? Most
likely a field in the section is Null, only blanks or a zero
length string. If so, then use code something like this to
suppress the section:

Cancel = (Nz(Trim([thefieldname]), "") = "")
 
M

Mona-ABE

You must be a teacher. I love the way you responded, because you didn't just
give the answer (which worked perfectly by the way), but you made me think
about it! Hopefully, it's added a new wrinkle to my brain.
--
Thanks again for the solution!
Mona-ABE


Marshall Barton said:
Mona-ABE said:
I have a report with 2 group headers and one detail section:
MODULE
BUSINESS
DETAIL

I always have module info, sometimes business info is empty, but the detail
section always has data for both. I'd like to supress the business header
and the corresponding detail section data when the business group header is
empty. Can you recommend the best way to do this either with VBA in the
report's onformat or onprint event, or some other way?


How can you tell if the group header has no data? Most
likely a field in the section is Null, only blanks or a zero
length string. If so, then use code something like this to
suppress the section:

Cancel = (Nz(Trim([thefieldname]), "") = "")
 
K

KLP

Marshall,

Where do you put that code? I am not well versed in VBA.

Thank you,
Kelvin

Marshall Barton said:
Mona-ABE said:
I have a report with 2 group headers and one detail section:
MODULE
BUSINESS
DETAIL

I always have module info, sometimes business info is empty, but the detail
section always has data for both. I'd like to supress the business header
and the corresponding detail section data when the business group header is
empty. Can you recommend the best way to do this either with VBA in the
report's onformat or onprint event, or some other way?


How can you tell if the group header has no data? Most
likely a field in the section is Null, only blanks or a zero
length string. If so, then use code something like this to
suppress the section:

Cancel = (Nz(Trim([thefieldname]), "") = "")
 
M

Mona-ABE

It works in the format event of the section you are wanting to cancel (i.e.
Private Sub GroupHeader1_Format or Private Sub Detail_Format).
--
Thanks!
Mona-ABE


KLP said:
Marshall,

Where do you put that code? I am not well versed in VBA.

Thank you,
Kelvin

Marshall Barton said:
Mona-ABE said:
I have a report with 2 group headers and one detail section:
MODULE
BUSINESS
DETAIL

I always have module info, sometimes business info is empty, but the detail
section always has data for both. I'd like to supress the business header
and the corresponding detail section data when the business group header is
empty. Can you recommend the best way to do this either with VBA in the
report's onformat or onprint event, or some other way?


How can you tell if the group header has no data? Most
likely a field in the section is Null, only blanks or a zero
length string. If so, then use code something like this to
suppress the section:

Cancel = (Nz(Trim([thefieldname]), "") = "")
 
K

KLP

I'm confused. My report has sub-reports. In the sub-report are several
fields. So I go into design mode on the sub-report, right click on DETAIL,
select properties, then Format, Print, Code Builder then insert the code
shown here?

Kelvin

Mona-ABE said:
It works in the format event of the section you are wanting to cancel (i.e.
Private Sub GroupHeader1_Format or Private Sub Detail_Format).
--
Thanks!
Mona-ABE


KLP said:
Marshall,

Where do you put that code? I am not well versed in VBA.

Thank you,
Kelvin

Marshall Barton said:
Mona-ABE wrote:

I have a report with 2 group headers and one detail section:
MODULE
BUSINESS
DETAIL

I always have module info, sometimes business info is empty, but the detail
section always has data for both. I'd like to supress the business header
and the corresponding detail section data when the business group header is
empty. Can you recommend the best way to do this either with VBA in the
report's onformat or onprint event, or some other way?


How can you tell if the group header has no data? Most
likely a field in the section is Null, only blanks or a zero
length string. If so, then use code something like this to
suppress the section:

Cancel = (Nz(Trim([thefieldname]), "") = "")
 
K

KLP

I want to hide a sub-report if there are no values in the sub-report, and
compress the report, that is, the other sections move up and the null section
does not appear at all.

Kelvin

Mona-ABE said:
It works in the format event of the section you are wanting to cancel (i.e.
Private Sub GroupHeader1_Format or Private Sub Detail_Format).
--
Thanks!
Mona-ABE


KLP said:
Marshall,

Where do you put that code? I am not well versed in VBA.

Thank you,
Kelvin

Marshall Barton said:
Mona-ABE wrote:

I have a report with 2 group headers and one detail section:
MODULE
BUSINESS
DETAIL

I always have module info, sometimes business info is empty, but the detail
section always has data for both. I'd like to supress the business header
and the corresponding detail section data when the business group header is
empty. Can you recommend the best way to do this either with VBA in the
report's onformat or onprint event, or some other way?


How can you tell if the group header has no data? Most
likely a field in the section is Null, only blanks or a zero
length string. If so, then use code something like this to
suppress the section:

Cancel = (Nz(Trim([thefieldname]), "") = "")
 
T

Theresa

Hi,
I have a similar problem except I want to hide a group header if an image is
not present. The situation is as follows:
Report Header
Group header 1 [this contains the image]
Group header 2 [also contains an image]
Details
If there is no image in the group headers 1 or 2 I want them no to display.
When I use the Cancel = Not Me.HasData the first record is hidden but then
it does not change for the next record that does have an image.
How do I force it to change for each record?
Thanks.
 
J

John Spencer

I think you need to check whether or not a control in the the Group header
has data or not.
Cancel = IsNull(Me.SomeControlName)

Of course that may fail with controls that are bound to images and you may
need a different test.

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

Theresa said:
Hi,
I have a similar problem except I want to hide a group header if an image
is
not present. The situation is as follows:
Report Header
Group header 1 [this contains the image]
Group header 2 [also contains an image]
Details
If there is no image in the group headers 1 or 2 I want them no to
display.
When I use the Cancel = Not Me.HasData the first record is hidden but then
it does not change for the next record that does have an image.
How do I force it to change for each record?
Thanks.
 

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