Query designer expression

What is wrong with this:

Total: =Sum([Amount]) where [EntryDate] between #1/1/2017# and #10/31/2017#
Who is Participating?
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.

Hamed NasrRetired IT ProfessionalCommented:
Where are you using this statement?
Upload the object using it.

First attempt: remove ':'
What error are you receiving?
SteveL13Author Commented:
Am using in a query designer as an expression.  I can't upload due to confidentiality issues.
Anders Ebro (Microsoft MVP)Microsoft DeveloperCommented:
The query expression can result in a field, but it can not directly have its own where clause, UNLESS you make it into a  subquery (which can be correlated if need be), or you could use a Dsum expression, but beware of performance implications of doing that, if implemented wrongly.
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Hamed NasrRetired IT ProfessionalCommented:
I can't upload due to confidentiality issues.
If I want to check, I need to recreate the issue, and not your database.
So I am asking you to recreate the issue with dummy data.
SteveL13Author Commented:
Let me see what I can put together
Gustav BrockCIOCommented:
You can use:

Total: =Sum(IIf([EntryDate]>=#1/1/2017# And [EntryDate]<=#10/31/2017#,[Amount],0))

Open in new window


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
Where are you trying to use this expression?
Hard-coding dates like this means constant change.  How should this really work?
SteveL13Author Commented:
I'll get something together tomorrow to show you. I thought this would be easy by if course it isn't.
Gus gave you a suggestion for how to incorporate the date range in the sum but context matters and the expression would be different depending on where you needed to run it.
SteveL13Author Commented:
I was able to use Gus' code with modification:

TotalCurrentPeriod: Sum(IIf([PostDate]>=[Forms]![frmSelectDateRange]![txtStartDate] And [PostDate]<=[Forms]![frmSelectDateRange]![txtEndDate],[Amount],0))

But I'm going to award points to all who contributed, because everyone provided insight that really helps me, and start a new topic title "Query Designer Help Please".
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.