I've had a different thought, one that should avoid the need for VBA
function.
To which field in your form's query is the combobox
"Annual_Operating_Hours_ID" bound? What is the RowSource query for this
combo box?
--
Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/
My subform is based on the query "Electrical_Cost_qry" which contains
fields
from 2 tables (Existing_Fixtures_tbl and Electrical_Costs_tbl) and is
in
datasheet view.
It contains the fields Project ID (tied to the main form) Fixture Qty,
Watts, Total Watts (unbound txt containing Fixture Qty * Watts),
Annual_Operating Hours (the cbo), Rate KWH, and Annual Cost (unbound
txt
containing Fixture_Qty * Watts * Annual_Operating_Hours_ID.Column(1) *
Rate
KWH /1000
Although I haven't typed the control sources exactly here, both of
these
calculations are working correctly.
I need to create a subtotal of all Annual Costs tied to a project.
:
You can only use field names from the form's RecordSource query/table
in
a
Sum expression. You cannot reference a control on the form, which is
what
you're trying to use:
[Annual_Operating_Hours_ID].[Column](1)
I assume that the form is in Continuous Forms view?
Only way I can think of right now to do what you want would be to
write a
VBA function that would read the form's Recordset data, look up the
related
value from Column(1) property of the combobox, do the calculation of
the
summed value, and then use that function in an expression for the
footer's
textbox's Control Source.
Tell us more about the form's setup/design.
--
Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/
OK....I got it working. Thanks.
Now I want to create a subtotal of that calculated field in the
form
footer.
I have an unbound textbox.
When I recreate the calculation and refer to column 1, I get an
error.
The
control source of the unbound subtotal field is:
=Sum([Fixture_Qty]*[Watts]*[Annual_Operating_Hours_ID].[Column](1)*[Rate
KWH]/1000)
The control source of the unbound textbox in the detail section of
the
subform is (this calculates correctly):
=[Fixture_Qty]*[Watts]*[Annual_Operating_Hours_ID].[Column](1)*[Rate
KWH]/1000
:
See this article:
http://www.mvps.org/access/forms/frm0058.htm
--
Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/
I have a subform (based on a query) which contains a bound
combobox
(linked
by an autonumber ID field) to look up the value in another
table. I
need
to
create an unbound field that using the value selected in the
combobox.
When
I select the ID field in my subform, the calculation uses the ID
number
rather than the related value. How can I it to use the value?