DCount Info

W

weircolin

Hi

Does anyone have any idea why when with the following code if I select
a year from "cboyear"
and nothing in "cbobenefits" the text box is giving me a return of "2"
rather than "0"?

=DCount("*","tblIssuesandconcerns","[Year] =" & Nz([cboyear],0) & "And
[Topic Name] =" & Nz([cbobenefits],0))

Cheers

Colin
 
D

Duane Hookom

Are we supposed to understand your data and field types? One small problem
might be the lack of a space to the left of "And..."
 
M

Marshall Barton

Does anyone have any idea why when with the following code if I select
a year from "cboyear"
and nothing in "cbobenefits" the text box is giving me a return of "2"
rather than "0"?

=DCount("*","tblIssuesandconcerns","[Year] =" & Nz([cboyear],0) & "And
[Topic Name] =" & Nz([cbobenefits],0))


The obvious reason for getting a nonzero count is because
there are some (two) records with a value of 0 in the
[Topic Name] field. If you can not find them, try runnung a
simple query directly from the query design window:
SELECT * FROM tblIssuesandconcerns WHERE [Topic Name]=0

When posting code, an expression or an SQL statement, please
use Copy/Paste so we don't waste time debugging typos. Your
expression as posted will not execute because of a missing
space.
 
J

John Vinson

Hi

Does anyone have any idea why when with the following code if I select
a year from "cboyear"
and nothing in "cbobenefits" the text box is giving me a return of "2"
rather than "0"?

=DCount("*","tblIssuesandconcerns","[Year] =" & Nz([cboyear],0) & "And
[Topic Name] =" & Nz([cbobenefits],0))

Cheers

Colin

Presumably because there are two records in tblIssuesandconcerns with
that year in the Year field and a zero value in the [Topic Name]
field. Try opening the table and check!

John W. Vinson[MVP]
 
W

weircolin

Thanks, wasn't thinking!

Colin
John said:
Hi

Does anyone have any idea why when with the following code if I select
a year from "cboyear"
and nothing in "cbobenefits" the text box is giving me a return of "2"
rather than "0"?

=DCount("*","tblIssuesandconcerns","[Year] =" & Nz([cboyear],0) & "And
[Topic Name] =" & Nz([cbobenefits],0))

Cheers

Colin

Presumably because there are two records in tblIssuesandconcerns with
that year in the Year field and a zero value in the [Topic Name]
field. Try opening the table and check!

John W. Vinson[MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top