Solved How to SUM value in subform via VBA code? (1 Viewer)

yunhsuan

Member
Local time
Today, 11:54
Joined
Sep 10, 2021
Messages
54
Hello~
I use SUM() to calculate value in subform on main Access Form by control data source (Below is "Test" file).
But the value would become unchangeable. So I want to calculate value by using VBA code.
I have tried to use DSum fn, but I failed. Maybe I used the wrong code.
Can any one tell me how to write the code?

Also, can SUM fn skip Null and properly calculate value?
 

Attachments

  • Test.accdb
    648 KB · Views: 259

June7

AWF VIP
Local time
Yesterday, 19:54
Joined
Mar 9, 2014
Messages
5,465
Aggregate functions ignore Null and only include records where field has data.

I hope you use better naming convention in real database. For starters, don't use spaces.

These work:
=[Table2]![Tax excluded]
=[Table2]![Taxes]
=[Table2]![Tax included]
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 23:54
Joined
Feb 19, 2002
Messages
43,223
These work:
=[Table2]![Tax excluded]
=[Table2]![Taxes]
=[Table2]![Tax included]
Isn't that interesting. Seems like the original version should be the one that works. Any idea why? Seems like yet another anomaly.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 11:54
Joined
May 7, 2009
Messages
19,231
Use query.
 

Attachments

  • test.accdb
    496 KB · Views: 269

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 23:54
Joined
Feb 19, 2002
Messages
43,223
June7 provided the solution. It was a reference style issue.
 

yunhsuan

Member
Local time
Today, 11:54
Joined
Sep 10, 2021
Messages
54
Thanks for suggestions! The problem was resolved successfully.
 

Users who are viewing this thread

Top Bottom