DCount with True/False criteria (1 Viewer)

gstylianou

Registered User.
Local time
Today, 14:40
Joined
Dec 16, 2013
Messages
357
Hi,

Just a question, How can I write correct the following function below to count only the records which the field [Active]=True?

a = DCount("[Patient_id]", "Patient Diseases", "[Patient_id] =" & Forms!MainForm.LogCustID)
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:40
Joined
May 7, 2009
Messages
19,245
a = DCount("1", "Patient Diseases", "Patient_ID = " & Forms!MainForm.LogCustID & " And [Active] = -1")
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 07:40
Joined
Feb 19, 2002
Messages
43,293
Keep in mind that Only Access uses -1 for true. So I would write --

& " AND [Active] = True"

to avoid any future issues.
 

MarkK

bit cruncher
Local time
Today, 04:40
Joined
Mar 17, 2004
Messages
8,181
Also...
Code:
a = -DSum("Active", "Patient Diseases", "[Patient_id] =" & Forms!MainForm.LogCustID)
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 07:40
Joined
Feb 19, 2002
Messages
43,293
Access treats anything <> 0 as true. That doesn't necessarily apply to any other RDBMS though. SQL Server uses 1 as True so if you ever might need to upsize, use True when checking for the true value and leave the details to the RDBMS to sort out.
 

Gasman

Enthusiastic Amateur
Local time
Today, 12:40
Joined
Sep 21, 2011
Messages
14,311
Access treats anything <> 0 as true. That doesn't necessarily apply to any other RDBMS though. SQL Server uses 1 as True so if you ever might need to upsize, use True when checking for the true value and leave the details to the RDBMS to sort out.
Thank you Pat.
I did a quick test this mornng to see that was actually the case.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 07:40
Joined
Feb 19, 2002
Messages
43,293
Oh ye of little faith:)

Sadly Access has numerous situations were it allows very sloppy processing in an effort to "save" the novice but being sloppy always has a price.
 

Users who are viewing this thread

Top Bottom