Function GetGrades(lngStudentID As Long) As String
Dim rst As DAO.Recordset
Dim strResult As String
Dim strLastGrade As String
Dim strSQL As String
Dim strDelim As String
strSQL = "SELECT Right$([Grade],1) AS GradeLetter, Count(Students) AS GradeCount From " & _
"(Select Students, Subject1 as Grade From result " & _
" Union All Select Students, Subject2 as Grade From result " & _
" Union All Select Students, Subject3 as Grade From result " & _
" Union All Select Students, Subject4 as Grade From result " & _
" Union All Select Students, Subject5 as Grade From result " & _
") as qry " & _
"Where students = " & lngStudentID & _
" GROUP BY Right$([Grade],1)"
Set rst = CurrentDb.OpenRecordset(strSQL)
strResult = "": strDelim = ""
While Not rst.EOF
strResult = strResult & strDelim & rst!GradeCount & rst!GradeLetter
strDelim = ","
rst.MoveNext
Wend
GetGrades = strResult
End Function
|