Solved Dcount yeild 0 (1 Viewer)

sbaud2003

Member
Local time
Today, 20:29
Joined
Apr 5, 2020
Messages
178
hi
i am using the Codes below bot result is Zero
Actually I want the user to get the number of Books available in the Library with the same title when select a particular book from the ComboBox "COMT"


Val = DCount("[Title]", "[BOOK]", "[Title] = " & "'" & Forms!FrmBook!COMT & "'")
 

moke123

AWF VIP
Local time
Today, 10:59
Joined
Jan 11, 2013
Messages
3,917
Val is a function so shouldn't be used as a variable name.

SomeVariable = DCount("*", "[BOOK]", "[Title] = """ & Forms!FrmBook!COMT & """")
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:59
Joined
Oct 29, 2018
Messages
21,468
Hi. For starters, try using something else than Val for the name of your variable.

Oops, too slow...
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:59
Joined
May 7, 2009
Messages
19,237
what is the Rowsource of your combo? how many Columns are there?
if only 1 column:

Val = DCount("[Title]", "[BOOK]", "[Title] = '" & Forms!FrmBook!COMT & "'")

if 2 column and first column is the bound column:

Val = DCount("[Title]", "[BOOK]", "[Title] = '" & Forms!FrmBook!COMT.Column(1) & "'")
 

Isaac

Lifelong Learner
Local time
Today, 07:59
Joined
Mar 14, 2017
Messages
8,777
You have some extra quotes in there...
 

sbaud2003

Member
Local time
Today, 20:29
Joined
Apr 5, 2020
Messages
178
what is the Rowsource of your combo? how many Columns are there?
if only 1 column:

Val = DCount("[Title]", "[BOOK]", "[Title] = '" & Forms!FrmBook!COMT & "'")

if 2 column and first column is the bound column:

Val = DCount("[Title]", "[BOOK]", "[Title] = '" & Forms!FrmBook!COMT.Column(1) & "'")
Thanks you sir,,,,,
Its working
One More Help Required
I am accessing the Title of the Book through the combo Box, name COMT through a query, but it displyas all the books of same name even they have diferent BOOK ID, I have applied Distinct clause but does not work....
Is there any way to list the name of the Books with single title even they have many in the library.
 

sbaud2003

Member
Local time
Today, 20:29
Joined
Apr 5, 2020
Messages
178
what is the Rowsource of your combo? how many Columns are there?
if only 1 column:

Val = DCount("[Title]", "[BOOK]", "[Title] = '" & Forms!FrmBook!COMT & "'")

if 2 column and first column is the bound column:

Val = DCount("[Title]", "[BOOK]", "[Title] = '" & Forms!FrmBook!COMT.Column(1) & "'")

Thanks you sir,,,,,
Its working
One More Help Required
I am accessing the Title of the Book through the combo Box, name COMT through a query, but it displyas all the books of same name even they have diferent BOOK ID, I have applied Distinct clause but does not work....
Is there any way to list the name of the Books with single title even they have many in the library.
 

sbaud2003

Member
Local time
Today, 20:29
Joined
Apr 5, 2020
Messages
178
what is the Rowsource of your combo? how many Columns are there?
if only 1 column:

Val = DCount("[Title]", "[BOOK]", "[Title] = '" & Forms!FrmBook!COMT & "'")

if 2 column and first column is the bound column:

Val = DCount("[Title]", "[BOOK]", "[Title] = '" & Forms!FrmBook!COMT.Column(1) & "'")
Thanks you sir,,,,,
Its working
One More Help Required
I am accessing the Title of the Book through the combo Box, name COMT through a query, but it displyas all the books of same name even they have diferent BOOK ID, I have applied Distinct clause but does not work....
Is there any way to list the name of the Books with single title even they have many in the library.
 

moke123

AWF VIP
Local time
Today, 10:59
Joined
Jan 11, 2013
Messages
3,917
but it displyas all the books of same name even they have diferent BOOK ID, I have applied Distinct clause but does not work....

if you have more than 1 column the whole row must be distinct.
"Select distinct Bookname, ID from tblBooks" - will return both name and id's that are unique. so if name is unique and ID isn't it will return all unique name/ID combinations.

"Select distinct Bookname from tblBooks" - will work
 

sbaud2003

Member
Local time
Today, 20:29
Joined
Apr 5, 2020
Messages
178
if you have more than 1 column the whole row must be distinct.
"Select distinct Bookname, ID from tblBooks" - will return both name and id's that are unique. so if name is unique and ID isn't it will return all unique name/ID combinations.

"Select distinct Bookname from tblBooks" - will work
thanks
 

Users who are viewing this thread

Top Bottom