I would place code to hide or display a subreport in the On Format event of
the section of the report that contains the subreport.
You should almost always be able to aggregate the value from a subreport's
record source into the main report's record source.
--
Duane Hookom
Microsoft Access MVP
:
Duane,
I need to view this report in Report view, so I guess I will go the route of
two subreports. I'm thinking the code to decide which subreport to display
will go in the OnOpen or OnLoad event of the main report. Is there a reason
to use one over the other in this case?
Also, the field I need to check to determine which subreport to use is
located in the subreport. Since the subreport won't be open yet I guess I'll
have to use a recordset to check the field--am I headed in the right
direction?
Thanks for sharing your expertise with me.
Kari
:
Allen Browne is correct as usual. The code will execute in some modes and
this is the simplest solution that I am can think of other than using two
different subreports.
--
Duane Hookom
Microsoft Access MVP
:
Duane,
For each Order (main report) each item in Order Details (subreport) will
either have an Item No or not, i.e. it will be the same for all detail
records in the same Order. Sorry I didn't make that clear.
I will be out of the office from now until Friday morning; I will try your
suggestions then. I'm a little worried about putting the code in the
OnFormat event of the subreport's detail section since I haven't been able to
get that event to fire when using the Report view (Access 2007). In another
post Allen Browne verified that it does not fire in Report view, which is
apparantly new to Access 2007.
I will be back in the fray on Friday. Thanks for all your help so far.
Kari
:
I would add a value to the tag property of every control you want to either
hide or move. For instance, select them all and enter "HasItemNum" in the tag
property. Create a new set of controls with the moved and wider text boxes.
Set the tag property of all these new text boxes to "NoItemNum".
It isn't clear if all the records in the subreport will have either Item
Numbers or not. You might need to add a text box in the subreport Header
Name: txtCountItemNum
Control Source: =Count([Item No])
Then add code to the On Format event of the subreport's detail section like:
Dim ctl as Control
For Each ctl in Me.Controls
If ctl.tag = "HasItemNum"
ctl.Visible = Me.txtCountItemNum > 0
End If
If ctl.tag = "NoItemNum"
ctl.Visible = Me.txtCountItemNum = 0
End If
--
Duane Hookom
Microsoft Access MVP
:
Chuck,
You make some good points; it *would* be disconcerting to have columns come
and go. However, this is a 1 page order sheet. The problem arises because
we have 1 customer (our largest customer naturally) that uses Item Numbers.
Luckily they don't use long Color names. So if I can use the space for one
or the other field I can keep the document in portrait orientation (much
easier to read when it is e-mailed to folks) and see everything I need to.
And keep the font large enough so that people can read it reasonably well.
Thanks for your 2 cents. It does help me understand why I haven't found any
one else trying to do something similar on the boards.
Kari
:
.>
For what little it's worth. When I'm reading a data report, I want all the
pages to have the same formatting. It would be disconcerting to have columns
come and go from page to page. Could it happen in the middle of a page? No
data - leave it blank or insert "n.a." You could use a smaller font or print
landscape. Just keep the report the same beginning to end.
Chuck