Access Sum not working as control source

Hi

I have an Access Report where the control source "[Invoice Details].[Amount]" works on a control but  "=Nz(Sum([Invoice Details].[Amount]),0)" does not.
It causes an error. This makes no sense to me.

Thanks
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fabrice LambertConsultingCommented:
Hi,

Is the control bound ?
Did you try with an unbound control and a query ?
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Maybe ...
=Sum(Nz( [Invoice Details].[Amount] , 0) )

What is the error ?
PatHartmanCommented:
The Sum() and other aggregate functions handle nulls.  You do not need to use Nz() in this situation.
Since Access does not support field names that contain dots, what is
[Invoice Details].[Amount]
referring to?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Maybe it needs to be:

=Sum([Amount])
mbizupCommented:
->>>  works on a control

The aggregate functions (SUM, AVG, etc) do not work on control names.  You need to use the name of the underlying field if it differs from the control name.  Check the control source property of your textbox.

If it is a simple fieldname use this in your aggregate function:
 
SUM (Field1)

Open in new window


For an expression use something like this:
SUM (Field1 + Field2)

Open in new window

PatHartmanCommented:
Correct but in that case, you will have to use Nz() if Field1 or Field2 might be null because  because Access performs the addition operation first and that will fail if either field is null event though the sum() handles nulls by ignoring them.

Sum(Nz(Field1,0) + Nz(Field2,0))
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
As a side note  I was assuming [Amount] is the Field name ....
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks for the advice
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
What was the actual problem ?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.