Dcount function (1 Viewer)

shamal

Registered User.
Local time
Yesterday, 23:03
Joined
Sep 28, 2013
Messages
77
Welcome
How can the Dcount function be used to calculate the following:
The number of students who failed in the fourth grade, Division A, in mathematics
 

Gasman

Enthusiastic Amateur
Local time
Today, 07:03
Joined
Sep 21, 2011
Messages
14,369
Use all three categories as criteria.
What they are is only known to you.

Put all the criteria into a string variable and debug.print that until you get it correct.
Then use that variable in the DCount() function.
 
Last edited:

AHeyne

Registered User.
Local time
Today, 08:03
Joined
Jan 27, 2006
Messages
93
If you want to use DCount, then this is only possible if all the information/fields are in the table/query you want to use as the source/domain for the DCount.
 

ebs17

Well-known member
Local time
Today, 08:03
Joined
Feb 7, 2020
Messages
1,952
DCount... just counts. A filter can be built into the third argument; this filter must have the same syntax as the WHERE part of an SQL statement without the WHERE keyword.

Overall, DCount is a query packaged as an access function. The best way to construct queries and perform calculations is to look at the database schema (unless you know it by heart), especially if there is more than one table to use.
Without this unknown information, you can hardly get concrete solutions from third parties.
 

Josef P.

Well-known member
Local time
Today, 08:03
Joined
Feb 2, 2023
Messages
833
Code:
? DCount("*", "StudentsTable", "not exists (select 1 from AnOtherTable where AnOtherTable.StudentID = StudentsTable.StudentID and ... ")
... I would test the Exists expression in a query.
But then you can also save this query and use it directly for DCount. ;)
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:03
Joined
May 21, 2018
Messages
8,555
Build an aggregate query returning count of students, group by class, division, course, pass/fail.
Now you have an easy dlookup to get
number of students in any grade, any division, any course, either pass or fail

dlookup("countofstudents","qryGroupBy", "Grade = 4 And Division = 'A' and Course = 'Mathmatics' and PassFail = 'Failed')
 

AHeyne

Registered User.
Local time
Today, 08:03
Joined
Jan 27, 2006
Messages
93
Code:
? DCount("*", "StudentsTable", "not exists (select 1 from AnOtherTable where AnOtherTable.StudentID = StudentsTable.StudentID and ... ")
... I would test the Exists expression in a query.
But then you can also save this query and use it directly for DCount. ;)
Nice, I never used a 'Select' in a domain functions condition at all. Like it!
 

AHeyne

Registered User.
Local time
Today, 08:03
Joined
Jan 27, 2006
Messages
93
I meant I have never formulated it myself in a condition as Josef has shown in #5.

This allows to access more tables/queries in the condition than specified in the domain parameter.
 
Last edited:

ebs17

Well-known member
Local time
Today, 08:03
Joined
Feb 7, 2020
Messages
1,952
You can also write a correct and complete query right away, including counting (DCount), determining the maximum (DMax) or determining the first value (DLookup, DFirst), and having the result passed to a custom function such as LookupSQL.
This opens up the available SQL world and you don't have to create a saved domain first.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 02:03
Joined
Feb 19, 2002
Messages
43,374
How can the Dcount function be used to calculate the following:
The number of students who failed in the fourth grade, Division A, in mathematics
dCount() would be an inefficient way to do this assuming that you also want counts of failures in other subjects and other divisions. If you used dCount() you would need a separate expression for each other group of criteria or you would need to run the dCount() x times passing in variable criteria.

More efficient would be to create a query that groups and counts all failures.

Select FailureIndictor, Grade, Division, Subject, Count(*) From YourGradeTable

You could then make a report bound to this query. That would leave you to using the dCount(), preferably with arguments, to produce a single count at a time.

You could also create a variation of this query that produces failure counts by teacher.
 

Users who are viewing this thread

Top Bottom