Avatar of Hamza Nadeem
Hamza Nadeem
 asked on

DCOUNT WITH MULTIPLE CRITERIA

Hi Guys,

I'm new to Microsoft access and am rock stuck at a formula. Would really appreciate your help.

=DCount("ACTIONS.[ID]","[ACTIONS]","[ACTIONS].T1000ID = " & [ID] AND [ACTIONS].[% COMPLETE] > 0.6)
I have also tried =DCount("ACTIONS.[ID]","[ACTIONS]","[ACTIONS].T1000ID = " & [ID] AND "[ACTIONS].[% COMPLETE] > 0.6") however I do not get the results I am looking for.

Basically I would like a count of ACTION IDs for two AND Conditions
1. The T1000ID is equal to ID
2. % Completion is > 0.6

Any assistance is really appreciated. This is driving me crazy

Thanks

Hamza
Microsoft Access

Avatar of undefined
Last Comment
Rey Obrero (Capricorn1)

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Rey Obrero (Capricorn1)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Hamza Nadeem

ASKER
Thank You so much Roy...that really helps.
Would you be able to recommend a resource (website/youtube) or book where I can learn the Syntax to avoid having problems in the future?

Thanks
Dale Fye

Hamza,

What I have found to work well for newbies is to actually do this work in the immediate window to start with, before incorporating it into a query, something like:

strCriteria = "([Actions].[T100ID] = 3)"
?DCount("[Actions].[ID]", "[Actions]", strCriteria)

Open in new window

If this prints out a value, then you know you have that syntax correct and can move on to the next segment:
strCriteria = "([Actions].[T100ID] = 3) AND ([Actions].[% COMPLETE] > 0.6)"
?DCount("[Actions].[ID]", "[Actions]", strCriteria)

Open in new window

If that works, then you can replace the hard coded values with the name of a field
DCOUNT("[Actions].[ID]", "[Actions]", "([Actions].[T100ID] = " & [ID] & ") AND ([Actions].[% COMPLETE] > 0.6)"

Open in new window

and place that in your query, or in the control Source of a control on a form.

The critical point when constructing criteria strings is that if the datatype of the field on the left of the = is a string, you must wrap the value you are comparing it to in quotes.  Ideally these would be double quotes, but because it gets confusing to use double quotes, many of us simply use single quotes.  So, lets assume that the [T100ID] field is a string.  In that case, the criteria string would look like:

strCriteria = "([Actions].[T100ID] = '3')"  
Note: notice the single quotes surrounding the '3'.  Then when you translate that to use the [ID] field, you would use:

strCriteria = "([Actions].[T100ID] = '" & [ID] & "')"
in this instance there is a singe quote 2 characters to the right of the = and another one character to the left of the ).  I like to wrap my individual criteria in ( ) because it helps me to visualize the individual parts of the logic of the criteria, plus it is easier to read.

Hope this helps.
Dale
Rey Obrero (Capricorn1)

@HAMZA

see this link for VBA tutorials  http://www.functionx.com/vbaccess/
Your help has saved me hundreds of hours of internet surfing.
fblack61
Rey Obrero (Capricorn1)

solution was provided