Dcount with miltiply criteria (1 Viewer)

TipsyWolf

Member
Local time
Today, 12:36
Joined
Mar 20, 2024
Messages
112
Hey guys !
i have difficalties with DCount. it says Invalid syntax.
im trying to count how many records i have using 2 criteria in 2 fileds - status1 and status2.
=Nz(DCount("status1";"Form";"status1='" & "rejected" & "' and "status2"="new'");0)

please help me out...
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 02:36
Joined
Oct 29, 2018
Messages
21,473
Looks like you were missing one single quote for the second criteria.

Sent from phone...
 

TipsyWolf

Member
Local time
Today, 12:36
Joined
Mar 20, 2024
Messages
112
Looks like you were missing one single quote for the second criteria.

Sent from phone...
u mean instead of "new'" i need to use "new"'" ?

DCount("Field1";"Form";"status1='" & "rejected" & "' and "status2"="new''")
i think i dont get where exactly i lost a quote. it didn't work though :(
 

AHeyne

Registered User.
Local time
Today, 11:36
Joined
Jan 27, 2006
Messages
92
If 'rejected' and 'new' are fix string literals (so no variables or controls) then you can use this:

Code:
=Nz(DCount("Field1";"Form";"status1='rejected' and status2='new'");0)

Edit: Please try to use code blocks in your postings. This makes code much more readable for us (see my code above).
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:36
Joined
Oct 29, 2018
Messages
21,473
u mean instead of "new'" i need to use "new"'" ?

DCount("Field1";"Form";"status1='" & "rejected" & "' and "status2"="new''")
i think i dont get where exactly i lost a quote. it didn't work though :(
No, I meant:

... =" & "'new'"

or better yet:

... ='" & "new" & "'"
 

Gasman

Enthusiastic Amateur
Local time
Today, 10:36
Joined
Sep 21, 2011
Messages
14,301
Put the criteria into a string variable.
Debug.print that until you get it correct.
Then use that variable in the function.
 

Users who are viewing this thread

Top Bottom