Solved DCount (1 Viewer)

hhag

Member
Local time
Today, 17:48
Joined
Mar 23, 2020
Messages
69
Hi,
I try to summarize the number of records with a specific field value.
I use the follwing vba code:
me.txtNumberOf=DCount("StatusID","tblOffer","StatusID=1")

I get error code 438; The object doesn't support the property or method.
The anoying thing is that I've other similar DCount expressions in the same module that works. The difference I see is that I don't set any criterie in these expressens that are the same as my expression above ("StatusID"). This might be the point? Is it possible to have 'expression' the same as 'Criteria'?

Grateful for some advice, thanks.
 

Ranman256

Well-known member
Local time
Today, 11:48
Joined
Apr 9, 2015
Messages
4,337
use asterisk:
=DCount("*","tblOffer","StatusID=1")

IF statusID is numeric.
if that field is a string , use delimiters:
=DCount("*","tblOffer","StatusID='1'")
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:48
Joined
Aug 30, 2003
Messages
36,126
Also make sure that's a textbox, not a label. If it's a label, you'd have to set its caption property.
 

hhag

Member
Local time
Today, 17:48
Joined
Mar 23, 2020
Messages
69
Thanks, good idea, but I still gives error... :-(
 

hhag

Member
Local time
Today, 17:48
Joined
Mar 23, 2020
Messages
69
I need to leave my PC for a couple of hours..
 

Isaac

Lifelong Learner
Local time
Today, 08:48
Joined
Mar 14, 2017
Messages
8,779
Your original code was fine. The error relates to setting the default property of txtNumberOf.
What kind of control is txtNumberOf ?
 

hhag

Member
Local time
Today, 17:48
Joined
Mar 23, 2020
Messages
69
Hi, really strange. I thought my first code was fine. And it was a textbox as well. I erased the textbox and created a new one. And then all of a sudden it worked.
Thanks all for your quick support! I appreciate it! 🙏 :)
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:48
Joined
Aug 30, 2003
Messages
36,126
Glad you got it sorted.
 

Users who are viewing this thread

Top Bottom