Ahhhhhhh, the fog clears.......
By way of clarification:
My database is trying to track consultations performed by
a medical professional.
A patient may have more than one service performed during
a given consultation.
So the relvant tables contain information relating to:
1) Item (Item#, Description ,Type etc)
2) ConsultItems (Consult#, Item#, Cost etc)
3) A consultation (Consult#, Patient#, Doctor#, Date etc)
4) A patient (Patient#, Name, address etc)
What I'm trying to do is provide a summary of services
rendered.
My main report has a record for each consultation. The
subreport (linked on Consult#) provides records for each
service performed during that consultation. My client
wants to see four columns with a "1" in the relevant one
for the type of service provided - of which there are
four (naturally).
My problem seems to lie with adding up values that are
derived from a field not in the recordsource.
My subreport uses ConsultItems as it's recordsource, but
the Type field is in Items. So in my subreport I've set
Item# up as a combo box and put my required fields in the
rowsource. Then when I refer to one of these fields I do
so like: [Item #].column(2)
So my txt box that works out whether or not this
particular service is of type "General" looks like this:
=IIf([Item #].column(2)="General",1,Null)
So, even in my subreport, I'm unable to perform the sum()
calculation that you've recommended. And it's apparently
all to do with the types of fields that I've used.
The question now is "so how do I fix it all?"
Some more background info:
My Items table contains ref data for all of the items
including a series of costs for each item depending on
the variety of client (eg full paying - concession etc).
It also contains the description of the item.
The ConsultItems tables is the keeper of info relating to
service items for a given consult. So it has links to
both Item# and Consult#. It also contains a field for
which Side of the body the service was performed on
(can't be stored in Items, because each Item# must relate
to only one service and these are dictated by the health
system), and another for Cost (calculated depending on
Item# and Patient variety).
Do I need to rethink my tables or can you see another way
around the reporting issue?
We're really moving now, you've identified the actual
cause of the problem!
Thanks again,
Debbie
-----Original Message-----
Comments inline below
--
Marsh
MVP [MS Access]
In the footer of the main report, I can use a statement
like:
=IIf(typefield = "A", 1, 0)
However when I put sum() around the expression:
=Sum(IIf(typefield = "A", 1, 0))
I thought the total was for data in the subreport??
I had suggested earlier that that expression should be used
in a text box in the subreport's footer section, did I
misunderstand what you're doing?
and run the report, it prompts me to enter the parameter
for the field name.
This probably means that the main report has a control (text
box?) named typefield, but the main report's recordsource
table/query does not have a field named typefield. The
aggregate functions (Count, Sum, etc) only operate on fields
in the recordsource of the form in which the function
appears. As I understood it from your previous posts, the
type field is in your subreport's recordsource query.
I'm reluctant to use a query as you've shown as if I ever
get this report working I hope to be able to run it iwith
date parameters etc and I think there's a fair chance
that I'll botch it up and the query will not take thee
other parameters into account!
Fear is no excuse ;-)
There are several ways to get the queries to use the same
parameters. You should note that I used your original query
in the From clause for my example query, just in case you
did have a complex set of criteria.
Am I trying to do this the hard way? I would have thought
that it would be a reasonably simple thing to calculate
totals within a subreport and transfer them to a main
report? Is there some really simple way to do this that
I've missed?
I think you are missing the easy way, but it's only a matter
of me explaining it so that you can get a grasp on how it's
done. Let me try another way.
Main report:
Subreport:
txtType: Type
Subreport Footer:
txtCountA: =Sum(IIf(Type = "A", 1, 0))
MainReport Footer:
txtTotalA: =subreport.Report.txtCountA
I hope this helps clarify how yhis sort of thing works.
Marsh, thanks for your advice so far.....I've been
stuffing about with this for weeks, now I feel like it's
progressing.
calculate
the expression
in better
off subreport.
For
.