DCount Additional Criteria

steve21nj

Registered User.
Local time
Today, 17:12
Joined
Sep 11, 2012
Messages
260
How would I add additional criteria to the below.

My criteria would be [myfield] = "Complete"

Is this even possible?

Code:
ThisYear: DCount("*","Open Issues","year([RequestDate]) = " & Year(DateAdd("y",-1,Date())))
 
Include AND or OR in the statement just as you would in an SQL Where clause.

BTW. Testing for the Year is not an efficient query because every record must have the Year function applied before deciding which records to return. The query will get slower and slower as the number of records increases.

The test should be of the date field directly against a date range generated from the current date. This will allow the engine to return records based on the date field's index without applying a function to every record.
 
To answer the Where Clause, would it look like this?

Code:
CompThisYear: DCount("*","Open Issues","year([RequestDate]) = " & Year(DateAdd("y",-1,Date())) And [MyField]='COMPLETE')

The second part, which makes sense but I'm not exactly sure how to build that.
 
As it stands it wuld look like this.

Code:
DCount("*","Open Issues","Year([RequestDate]) = " & Year(DateAdd("y",-1,Date())) & " And [MyField]='COMPLETE'")

However you are apparently using the DCount in a query. This will be even slower because each DCount is like running a query.

Investigate how to do the entire job in an aggregate query.
 

Users who are viewing this thread

Back
Top Bottom