Sorry again about that one. I hope this set should do it. Here's the updated function in your module:
Public Function GetGroupIDName(ByVal courseGroup As String) As String
Dim db As Database
Dim rs As Recordset
Dim sql As String
sql = "SELECT IIf([Course] In (""Physics"",""Chemistry""),""Physics, Chemistry"",[Course]) AS CourseGroup, tblMain.GroupID, Count(tblMain.RID) AS CountOfRID " & _
" FROM tblMain INNER JOIN tblCourse ON tblMain.CourseID = tblCourse.CourseID " & _
" WHERE IIf([Course] In (""Physics"",""Chemistry""),""Physics, Chemistry"",[Course])=""" & Replace(courseGroup, """", """""") & """" & _
" GROUP BY IIf([Course] In (""Physics"",""Chemistry""),""Physics, Chemistry"",[Course]), tblMain.GroupID;"
Set db = CurrentDb()
Set rs = db.OpenRecordset(sql)
Dim i As Integer
Dim returnString As String
returnString = ""
If rs.RecordCount > 0 Then
rs.MoveFirst
For i = 0 To rs.RecordCount - 1
If i <> rs.RecordCount - 1 Then
returnString = returnString & rs!GroupID & ", "
Else
returnString = returnString & rs!GroupID
End If
rs.MoveNext
Next i
End If
GetGroupIDName = returnString
End Function
And here's the updated query:
SELECT GetGroupIDName(IIf([Course] In ("Physics","Chemistry"),"Physics, Chemistry",[Course])) AS GroupID, IIf([Course] In ("Physics","Chemistry"),"Physics, Chemistry",[Course]) AS CourseGroup, Count(tblMain.RID) AS CountOfRID
FROM tblMain INNER JOIN tblCourse ON tblMain.CourseID = tblCourse.CourseID
WHERE (((tblMain.Appdate)>=[forms]![frmReportDateRange]![BeginDate] And (tblMain.Appdate)<=[forms]![frmReportDateRange]![EndDate]))
AND Not NZ(tblMain.CCon,false)
GROUP BY GetGroupIDName(IIf([Course] In ("Physics","Chemistry"),"Physics, Chemistry",[Course])), IIf([Course] In ("Physics","Chemistry"),"Physics, Chemistry",[Course])
ORDER BY Last(tblCourse.CourseID);