Dcount with Multiple Conditions (1 Viewer)

Ksabai

Registered User.
Local time
Today, 03:33
Joined
Jul 31, 2017
Messages
104
Iam getting error with the following Line:

If DCount("[Duty]", "tblstaff", "[SellerID]= sSellerID And ([Duty] = 8 Or [Duty] = 12)") >= 1 Then
Also tried - If DCount("[Duty]", "tblstaff", "[SellerID]=" & sSellerID And "([Duty] = 8 Or [Duty] = 12)") >= 1 Then
sSellerID is an Integer

Can Someone help
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:33
Joined
May 7, 2009
Messages
19,243
if SellerID is string:

If DCount("[Duty]", "tblstaff", "[SellerID]= '" & sSellerID & "' And ([Duty] = 8 Or [Duty] = 12)") >= 1

or Numeric:

If DCount("[Duty]", "tblstaff", "[SellerID]= " & sSellerID & " And ([Duty] = 8 Or [Duty] = 12)") >= 1

also you can use Nz() function, in case tblStaff has no record yet, eg:

If Nz(DCount("[Duty]", "tblstaff", "[SellerID]= " & sSellerID & " And ([Duty] = 8 Or [Duty] = 12)"), 0) >= 1
 

June7

AWF VIP
Local time
Today, 02:33
Joined
Mar 9, 2014
Messages
5,472
If there are no records in table, DCount() will return 0 so Nz is not needed.
 

Bullschmidt

Freelance DB Developer
Local time
Today, 05:33
Joined
May 9, 2019
Messages
40
Yes isn't it interesting that DSum() and DMax() need the Nz() (to convert a Null to 0) but DCount() does not...
 

June7

AWF VIP
Local time
Today, 02:33
Joined
Mar 9, 2014
Messages
5,472
I think DCount() is the only domain aggregate that does not return Null.
 

Users who are viewing this thread

Top Bottom