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')