When query returns null, I need a zero value as results are used in another query

I have looked over the answers to what seems to be this question, but do not get them to work.  What I have is a query that if there are no rows to count, does not give me any return value, ie., Null.  However, the results of this query are used in another query and I must have a zero value-otherwise the second query gives me all nulls for the other fields in it despite the fact that their base queries do return values.

SELECT IIf(IsNull(Count([tblDocumentsReturned].[Account])),0,(Count([tblDocumentsReturned].[Account]))) AS MutualFund
FROM tblDocumentsReturned
WHERE (((tblDocumentsReturned.DateReceived)<=[FORMS]![frmMatrixDialog]![txtEnd]) AND ((tblDocumentsReturned.DocStatus)="Mutual Fund"))
GROUP BY tblDocumentsReturned.Product
HAVING (((tblDocumentsReturned.Product)=[FORMS]![frmMatrixDialog]![lstProduct]));

Thanks
Sandra SmithRetiredAsked:
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.

EagleEye1975Commented:
There should be a few ways around this, but we really need to know what development environment you're using.

There should be a way to get the number of rows returned by the query... that's the first type of function I'd look for.

If there is no such function, you can do an error trap, saying "If (whatever) = null, NumRows = 0"

That way, your NULL becomes a zero, and that later function doesn't work with a bunch of NULL values.
0
BillJenningsCommented:
I'm guessing this is MS-Access.

It looks to me like this query returns a row for each record from tblDocumentsReturned that meets the criteria, and each of these rows contains a single field (called MutualFund) containing the total number of rows in tblDocmuentsReturned.

Now,  I'm not sure where you want the zero to be returned.  If there are no rows in tblDocumentsReturned that meet the criteria, it will not return any rows.  Do you want it to always return at least one row?  If so, where would the zero go?

Sincerely
Bill Jennings
0
EagleEye1975Commented:
Are you going to give more information or accept an answer?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Sandra SmithRetiredAuthor Commented:
Sorry, I have been out of the office, but am glad for the responses.  What I have is another query based on the results of multiple count queries that combines all these results to be used in a final report.  
0
Sandra SmithRetiredAuthor Commented:
I am using Access mdb database
0
EagleEye1975Commented:
Yeah, it's pretty simple then...

All of those count queries need to say "If count = null then count = 0"... so that when they're added together you're not trying to add null, you're adding zero instead.

Add a layer of abstraction in... don't use the count query results themselves in the adding up of the total.  Do the count queries, and have each result be evaluated and put a final result in to a variable (this would all be done in a module)... then evaluate the variables... if null, then make them equal zero instead... add the result variables, and you have your total without nulls. :)
0

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
BillJenningsCommented:
BTW

"if [count] == null then [count] = 0" can be done inside the query with:

cnt: nz([count])

then use [cnt] wherever you were going to use [count].

Sincerely

Bill Jennings
0
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
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.