Thanks to everybody who has helped me to get this thing finally working
(somewhat). I got the field names to properly display in the
PageHeaderSection, so I won't post the code from that. Now I'm trying to
populate the records (this is based on a cross-tab query "qryTableOfGrades"
in the Detail section but it only displays the data from the last record in
every record. Here's the code. I wonder what I'm doing wrong:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim rs As DAO.RecordSet
Dim db As DAO.Database
Dim qdf As QueryDef
Dim i As Integer
Dim j As Integer
Dim intNumOfFields As Integer
Dim intRecordCount As Integer
Set db = CurrentDb
Set qdf = db.QueryDefs("qryTableOfGrades")
With qdf
.Parameters("[Forms]!frmSelectCourse]![cboSelectCourse") =
[Forms]![frmSelectCourse]![cboSelectCourse]
End With
Set rs = qdf.OpenRecordset()
rs.MoveLast
intRecordCount = rs.RecordCount
rs.MoveFirst
intNumOfFields = rs.Fields.Count
'Populate data labels
'The first three fields contain student names, course number, and course
discription and don't get used here.
For i = 4 To 45 ' make empty labels invisible.
Me.Controls("lblData" & i).Caption = ""
Me.Controls("lblData" & i).Visible = False
Next i
For j = 1 To intRecordCount
For i = 4 To intNumOfFields - 1 'I don't need the first three fields
here.
Me.Controls("lblData" & i).Visible = True 'make useable labels
visible
Me.Controls("lblData" & i).Caption = rs.Fields(i)
Next i
Next j
Set qdf = Nothing
Set rs = Nothing
set db = Nothing
End Sub