Dcount Null (2 Viewers)

cybersardinha

New member
Local time
Today, 16:04
Joined
Mar 24, 2022
Messages
24
Hi,

I'm hitting a bit of a problem.

I have this formula on VBA:

Code:
ngultig = DCount("*", sTblName, mFB & " < " & sExpired)

It works and it gives me the right results but I wanted it not only to count the values inferior to sExpired but also the fields that are empty/null on that column.

Is This possible?

Thanks
 

plog

Banishment Pending
Local time
Today, 09:04
Joined
May 11, 2011
Messages
11,653
Add an OR to it to include your additional logic:

... OR IsNull(YourField)
 

CJ_London

Super Moderator
Staff member
Local time
Today, 15:04
Joined
Feb 19, 2013
Messages
16,629
try

ngultig = DCount("*", sTblName, nz(mFB,0) & " < " & sExpired)

or

ngultig = DCount("*", sTblName, mFB & " < " & sExpired OR isnull(mFB))
 

cybersardinha

New member
Local time
Today, 16:04
Joined
Mar 24, 2022
Messages
24
try

ngultig = DCount("*", sTblName, nz(mFB,0) & " < " & sExpired)

or

ngultig = DCount("*", sTblName, mFB & " < " & sExpired OR isnull(mFB))

I've tried it, the first option just gives me the < sExpired count and the second one stops the code and doesn't give any output.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 15:04
Joined
Feb 19, 2013
Messages
16,629
I just modified the code you say works. If the first one is giving you the same result, implies there are no nulls.

the second one, I've probably missed out an & somewhere

in both cases since mFB is not surrounded with quotes, it will be a vba value, not one in the table. I would have expected

"[mFB] < " & sExpired

or for my first example

"nz([mFB]) < " & sExpired

same goes for sExpired
 

cybersardinha

New member
Local time
Today, 16:04
Joined
Mar 24, 2022
Messages
24
yes both are VBA values. the mFB contains the table name and the sExpired contains a date that is calculated by subtracting a number of months to the current date.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 15:04
Joined
Feb 19, 2013
Messages
16,629
So how do you think dcount works? Lets call your table 'tableX' and you are subtracting 6 months from todays date.

Based on what you are saying then your criteria is

'tableX < 2022-01-07'

just don't see how that works
 

Users who are viewing this thread

Top Bottom