Dcount with miltiply criteria

TipsyWolf

Member
Local time
Today, 15:32
Joined
Mar 20, 2024
Messages
249
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:
Looks like you were missing one single quote for the second criteria.

Sent from phone...
 
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 :(
 
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).
 
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" & "'"
 
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

Back
Top Bottom