Hiding report section headers and footers as needed with code

D

Doug

I have a report which contains info for and is sorted by SampleNumber
and BottleType. There is a header and footer for each sort section.
There are occasions when one sample on an order with many samples is
cancelled. On those occasions, for that sample only I'd like to hide
the BottleType header, data, and footer and simply print a line that
says "This sample has been cancelled because of [Reason]."

I've been trying to work with the "Visible" properties for the header,
footer, etc. setting them to False if the query returns a Not IsNull
for the [Reason] field. The problem is that it's an all or none
situation. If there is one cancelled sample, the headers, footers,
etc. are hidden for ALL of the samples on the entire report.

It seems I need a loop to check the first record for a reason and set
the properties accordingly, then check the next record, set the
properties, then check the next record, etc...

Am I approaching this the right way? Is there a better way to do this
or do I just need to get the code right?

Any help would be greatly appreciated.

Thanks.
Doug
 
B

Bob Quintal

I have a report which contains info for and is sorted by
SampleNumber and BottleType. There is a header and footer for each
sort section. There are occasions when one sample on an order with
many samples is cancelled. On those occasions, for that sample
only I'd like to hide the BottleType header, data, and footer and
simply print a line that says "This sample has been cancelled
because of [Reason]."

I've been trying to work with the "Visible" properties for the
header, footer, etc. setting them to False if the query returns a
Not IsNull for the [Reason] field. The problem is that it's an all
or none situation. If there is one cancelled sample, the headers,
footers, etc. are hidden for ALL of the samples on the entire
report.

It seems I need a loop to check the first record for a reason and
set the properties accordingly, then check the next record, set
the properties, then check the next record, etc...

Am I approaching this the right way? Is there a better way to do
this or do I just need to get the code right?

Any help would be greatly appreciated.

Thanks.
Doug
Where are you setting the .visible properties?


are you using the ELSE portion of the IF statement to turn the
visible= true again?

private sub footer0_Format()
if NOT Isnull([REASON]} then
me.footer0.visible = false
Else
me.footer0.visible = true
End IF
end sub

or alternatively:

me.footer0.visible = isnull([REASON])

which does everything in one line
 
M

Marshall Barton

Doug said:
I have a report which contains info for and is sorted by SampleNumber
and BottleType. There is a header and footer for each sort section.
There are occasions when one sample on an order with many samples is
cancelled. On those occasions, for that sample only I'd like to hide
the BottleType header, data, and footer and simply print a line that
says "This sample has been cancelled because of [Reason]."

I've been trying to work with the "Visible" properties for the header,
footer, etc. setting them to False if the query returns a Not IsNull
for the [Reason] field. The problem is that it's an all or none
situation. If there is one cancelled sample, the headers, footers,
etc. are hidden for ALL of the samples on the entire report.

It seems I need a loop to check the first record for a reason and set
the properties accordingly, then check the next record, set the
properties, then check the next record, etc...

Am I approaching this the right way? Is there a better way to do this
or do I just need to get the code right?


The all or none problem is probably caused by you setting
Visible = False without ever setting it to True. You code
should look something like:

If Not IsNull(Me.Reason) Then
Me.Section(5).Visible = True
Me.Section(6)).Visible = True
. . .
Else
Me.Section(5).Visible = False
Me.Section(6)).Visible = False
. . .
End If

Or, using fewer lines of code, with the same effect:

bolIsReason = Not IsNull(Me.Reason)
Me.Section(5).Visible = bolIsReason
Me.Section(6)).Visible = bolIsReason
. . .

I'm not sure where you want the cancelled message to appear,
but you probably want to use a text box in the group header
to display the message. Then, instead of making the section
invisible, make all of it's controls visible/invisible and
the cancelled text box the other way.
 
D

Doug

Doug said:
I have a report which contains info for and is sorted by SampleNumber
and BottleType. There is a header and footer for each sort section.
There are occasions when one sample on an order with many samples is
cancelled. On those occasions, for that sample only I'd like to hide
the BottleType header, data, and footer and simply print a line that
says "This sample has been cancelled because of [Reason]."
I've been trying to work with the "Visible" properties for the header,
footer, etc. setting them to False if the query returns a Not IsNull
for the [Reason] field. The problem is that it's an all or none
situation. If there is one cancelled sample, the headers, footers,
etc. are hidden for ALL of the samples on the entire report.
It seems I need a loop to check the first record for a reason and set
the properties accordingly, then check the next record, set the
properties, then check the next record, etc...
Am I approaching this the right way? Is there a better way to do this
or do I just need to get the code right?

The all or none problem is probably caused by you setting
Visible = False without ever setting it to True. You code
should look something like:

If Not IsNull(Me.Reason) Then
Me.Section(5).Visible = True
Me.Section(6)).Visible = True
. . .
Else
Me.Section(5).Visible = False
Me.Section(6)).Visible = False
. . .
End If

Or, using fewer lines of code, with the same effect:

bolIsReason = Not IsNull(Me.Reason)
Me.Section(5).Visible = bolIsReason
Me.Section(6)).Visible = bolIsReason
. . .

I'm not sure where you want the cancelled message to appear,
but you probably want to use a text box in the group header
to display the message. Then, instead of making the section
invisible, make all of it's controls visible/invisible and
the cancelled text box the other way.

--
Marsh
MVP [MS Access]- Hide quoted text -

- Show quoted text -

I tried with and without the Else setting Visible=True. It didn't seem
to make a difference.
And, yes, on the section where I want the reason to display I'm
setting the controls to invisible. I figured if I get the headers to
hide properly, I can figure out how to get the controls to follow. I
simplified the example for brevity's sake.

I'll try again. Maybe I missed something in the code. I'll let you
know.

Thanks
 
D

Doug

I have a report which contains info for and is sorted by
SampleNumber and BottleType. There is a header and footer for each
sort section. There are occasions when one sample on an order with
many samples is cancelled. On those occasions, for that sample
only I'd like to hide the BottleType header, data, and footer and
simply print a line that says "This sample has been cancelled
because of [Reason]."
I've been trying to work with the "Visible" properties for the
header, footer, etc. setting them to False if the query returns a
Not IsNull for the [Reason] field. The problem is that it's an all
or none situation. If there is one cancelled sample, the headers,
footers, etc. are hidden for ALL of the samples on the entire
report.
It seems I need a loop to check the first record for a reason and
set the properties accordingly, then check the next record, set
the properties, then check the next record, etc...
Am I approaching this the right way? Is there a better way to do
this or do I just need to get the code right?
Any help would be greatly appreciated.
Thanks.
Doug

Where are you setting the .visible properties?

are you using the ELSE portion of the IF statement to turn the
visible= true again?

private sub footer0_Format()
if NOT Isnull([REASON]} then
me.footer0.visible = false
Else
me.footer0.visible = true
End IF
end sub

or alternatively:

me.footer0.visible = isnull([REASON])

which does everything in one line

I've tried placing all of the code in the On Format event for the
group header and also in the Reports On Open event.

Hmm, is that the problem? Should I be splitting that code up for the
On Format for each section (header0, footer0, header1,footer1)? I'll
try that also.
 
M

Marshall Barton

Doug said:
Doug said:
I have a report which contains info for and is sorted by SampleNumber
and BottleType. There is a header and footer for each sort section.
There are occasions when one sample on an order with many samples is
cancelled. On those occasions, for that sample only I'd like to hide
the BottleType header, data, and footer and simply print a line that
says "This sample has been cancelled because of [Reason]."
I've been trying to work with the "Visible" properties for the header,
footer, etc. setting them to False if the query returns a Not IsNull
for the [Reason] field. The problem is that it's an all or none
situation. If there is one cancelled sample, the headers, footers,
etc. are hidden for ALL of the samples on the entire report.
It seems I need a loop to check the first record for a reason and set
the properties accordingly, then check the next record, set the
properties, then check the next record, etc...
Am I approaching this the right way? Is there a better way to do this
or do I just need to get the code right?

The all or none problem is probably caused by you setting
Visible = False without ever setting it to True. You code
should look something like:

If Not IsNull(Me.Reason) Then
Me.Section(5).Visible = True
Me.Section(6)).Visible = True
. . .
Else
Me.Section(5).Visible = False
Me.Section(6)).Visible = False
. . .
End If

Or, using fewer lines of code, with the same effect:

bolIsReason = Not IsNull(Me.Reason)
Me.Section(5).Visible = bolIsReason
Me.Section(6)).Visible = bolIsReason
. . .

I'm not sure where you want the cancelled message to appear,
but you probably want to use a text box in the group header
to display the message. Then, instead of making the section
invisible, make all of it's controls visible/invisible and
the cancelled text box the other way.

I tried with and without the Else setting Visible=True. It didn't seem
to make a difference.
And, yes, on the section where I want the reason to display I'm
setting the controls to invisible. I figured if I get the headers to
hide properly, I can figure out how to get the controls to follow. I
simplified the example for brevity's sake.


The code I posted needs to be in the sample header section's
Format event procedure. Note that I used section numbers (5
for sample header and 6 for sample footer) that may be
different in your report, depending on whether you have more
groups above the sample group (in Sorting and Grouping).
You can use the actual names of the header/footer sections
instead. i.e. Any of these will work:

Me.Section(5).Visible = bolIsReason
or
Me.Section(acGroupLevel1Header).Visible = bolIsReason
or
Me.GroupFooter0.Visible = bolIsReason
where GroupFooter0 is Access' default name that you might
have changed to a more descriptive name.
 
D

Doug

Doug said:
Doug wrote:
I have a report which contains info for and is sorted by SampleNumber
and BottleType. There is a header and footer for each sort section.
There are occasions when one sample on an order with many samples is
cancelled. On those occasions, for that sample only I'd like to hide
the BottleType header, data, and footer and simply print a line that
says "This sample has been cancelled because of [Reason]."
I've been trying to work with the "Visible" properties for the header,
footer, etc. setting them to False if the query returns a Not IsNull
for the [Reason] field. The problem is that it's an all or none
situation. If there is one cancelled sample, the headers, footers,
etc. are hidden for ALL of the samples on the entire report.
It seems I need a loop to check the first record for a reason and set
the properties accordingly, then check the next record, set the
properties, then check the next record, etc...
Am I approaching this the right way? Is there a better way to do this
or do I just need to get the code right?
The all or none problem is probably caused by you setting
Visible = False without ever setting it to True. You code
should look something like:
If Not IsNull(Me.Reason) Then
Me.Section(5).Visible = True
Me.Section(6)).Visible = True
. . .
Else
Me.Section(5).Visible = False
Me.Section(6)).Visible = False
. . .
End If
Or, using fewer lines of code, with the same effect:
bolIsReason = Not IsNull(Me.Reason)
Me.Section(5).Visible = bolIsReason
Me.Section(6)).Visible = bolIsReason
. . .
I'm not sure where you want the cancelled message to appear,
but you probably want to use a text box in the group header
to display the message. Then, instead of making the section
invisible, make all of it's controls visible/invisible and
the cancelled text box the other way.
I tried with and without the Else setting Visible=True. It didn't seem
to make a difference.
And, yes, on the section where I want the reason to display I'm
setting the controls to invisible. I figured if I get the headers to
hide properly, I can figure out how to get the controls to follow. I
simplified the example for brevity's sake.

The code I posted needs to be in the sample header section's
Format event procedure. Note that I used section numbers (5
for sample header and 6 for sample footer) that may be
different in your report, depending on whether you have more
groups above the sample group (in Sorting and Grouping).
You can use the actual names of the header/footer sections
instead. i.e. Any of these will work:

Me.Section(5).Visible = bolIsReason
or
Me.Section(acGroupLevel1Header).Visible = bolIsReason
or
Me.GroupFooter0.Visible = bolIsReason
where GroupFooter0 is Access' default name that you might
have changed to a more descriptive name.

--
Marsh
MVP [MS Access]- Hide quoted text -

- Show quoted text -

I got it. I put the code for each header in its own On Focus property
and added the Else settings and it works like a charm.

Thank you both!
 

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