Sum(IIF()) based on Query not working

Hello,

I have the following but can't get it to work right...looked all around but can't seem to figure out what I am doing wrong...

=Sum(IIf("qryMG30551rptDateOnly",[Twic]="Yes",1))


All I get is the Error...
Ernest GroggSecurity Management InfoSecAsked:
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.

Rey Obrero (Capricorn1)Commented:
try using Dcount()

=Dcount("*","qryMG30551rptDateOnly","[Twic]='Yes'")

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
BitsqueezerCommented:
Hi,

DCount is not the same as Sum...;-)
So you would need to use DSum ist that's a formula used in a field (because you have "=" at the beginning). Instead of "*" which Rey used above (and works with DCount) you would need to add the fieldname of the query which you want to sum in the first parameter.

Please keep in mind that using a formula in a field will cause a delay until the result is displayed, and it will need an extra round trip to the backend database. If you want to avoid that you should insert the calculation of the sum into the query which you use for the form so it will be displayed immediately.

Cheers,

Christian
Rey Obrero (Capricorn1)Commented:
if the field [Twic] is Boolean type, YesNo

use
=Dcount("*","qryMG30551rptDateOnly","[Twic]=-1")

@Christian
DCount is not the same as Sum...;-) - very true, if you will compare them directly, but if use SUM with IIF function in a query it will produce the same result..

Sum(IIF([qryMG30551rptDateOnly].[Twic]="Yes",1,0))
Rey Obrero (Capricorn1)Commented:
if the field [Twic] is Boolean type, YesNo, you can use Dsum()

=dsum("chic","qryMG30551rptDateOnly") * -1
Ernest GroggSecurity Management InfoSecAuthor Commented:
Thanks for all the help!  Sorry I didn't respond sooner.  I like the explanations too.  

Also, I never even considered the dsum.  Nice!
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.