Answers below, and thanks!
Hi Steve
Let's get a few things straight here. I understand that:
1. Your "Computers form" is a main form Yes
2. It contains a subform control named "MaintenanceSbf" Yes
3. This subform control has both LlinkMasterFields and LinkChildFields
set
to "ComputerID"Yes (
4. The subform contained in that control has a field named
"MaintenanceCost"
5. You have a textbox in the footer of that subform named "Total
Maintenance Cost" (BTW, I advise against using non-alphanumeric
characters, including spaces, in fieldnames or control names). I
changed it to TotalMaintenanceCost
6. The control source of this textbox is:
=Nz(Sum([MaintenanceCost]), 0)
7. On the main form you have a textbox whose control source is:
=[MaintenanceSbf].[Form]![Total Maintenance Cost]
Please tell me if ANY of the premises above is incorrect.
Now some questions: What do you see in (a) the total textbox on the
subform and (b) the total textbox on the main form in each of the
following cases:
1. The current computer has one or more maintenance records with a
non-null value for MaintenanceCost?
2. The current computer has one or more maintenance records, but they
all
have a null value for MaintenanceCost?
3. The current computer does not have any related maintenance records?
Am I correct that the problem occurs only in the third case? Yes
If so, then add another textbox to your main form named
"txtMaintenanceCount". Set its control source to the following:
=[MaintenanceSbf].[Form].[Recordset].[RecordCount]
Now, change the controlsource of the textbox in (7) above to:
=IIf([txtMaintenanceCount]=0, 0, [MaintenanceSbf].[Form]![Total
Maintenance Cost])
Try it and report back. It didn't work. The txtMaintenanceCount
returns Name? and the box (7 above) is also Name?
Don't feel that you're wasting anybody's time. We do this because we
like
to help. I would only consider I had wasted my time if you gave up
before
reaching a solution
--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand
OK, Graham, I have wasted enough of your time, and you have my deepest
appreciation. What you wrote worked like a charm on my Locations Form
for
accessories and computers cost. However, it does not seem to work on
my
Computers Form with Maintenance Subform.
Current Configuration: It works if totals are not null
On MaintenanceSbf, I have a field that is labeled Total Maintenance
Cost
and
the Control Source is =Sum[MaintenanceCost])
On Computers form, I have a field that is labeled Total Maintenance
and
the
Control Source is
=IIf(IsNull([ComputerID]),0,DSum("[MaintenanceCost]","Maintenance","[ComputerID]="
& [ComputerID]))
I tried to change it to:
On MaintenanceSbf, Total Maintenance Cost and the Control Source is
=Nz(Sum([MaintenanceCost]), 0)
On Computers form, I have a field that is labeled Total Maintenance
and
the
Control Source is
[MaintenanceSbf].Form![Total Maintenance Cost]
This begets #Name?
I think the problem may be something to do with ComputerID stuff.
Thanks
again, and I promise this is my last post.
Hi Steve
The idea of using a textbox to count the records in the subform is
simply so you can get around the problem of "#Error!" when there are
no
records to sum. You don't need to *display* the txtCount textbox if
you
don't want to - just set its Visible property to False.
If there are records in your subform, but all of them have Null in
the
Maintenance field, then =Sum([Maintenance]) will return Null also.
Then, if you try to add Null to a number, that also will return Null.
The trick is to use the Nz function to convert the Null to zero, and
then you can add it. So change the SumMaintenance control source to:
=Nz(Sum([Maintenance]), 0)
As John explained, there is a difference between DataEntry and
AllowAdditions. DataEntry suppresses the display of existing
records,
allowing you only to add new ones. If DataEntry is False and
AllowAdditions is True, then you can view/edit existing records *and*
add new ones.
--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand