Dear Reader,
I've created a datareport in VB6 without using the data environment. There is one grouping level, achieved using the SHAPE command. The report displays data in the correct format (group header and correct number of child records for each parent), but only works if I assign a parent column as the datafield of the child fields in the detail section. If I try to assign one of the child columns to the child field then I get the "DataField <name> not found".
Code is below, any ideas greatly appreciated.
Dim strSQL As String, strSQL2 As String
Dim rep As New rptStudGradesHT2
Dim rstRepData As ADODB.Recordset
strSQL = "SELECT tblStudents.ID, CONCAT(tblStudents.LName, ', ', tblStudents.FName) AS Name, tblHouses.Name as House, If(tblClassTut.Year<10, Right(tblClassTut.Name, 2), CONCAT(Trim(tblClassTut.Year), Left(tblHouses.Name,1))) as Class, tblClassTut.Year "
strSQL = strSQL & "FROM tblClassTut, tblHouses, tblStudents "
strSQL = strSQL & "WHERE tblClassTut.ID = tblStudents.Class AND tblHouses.ID = tblStudents.House "
strSQL = strSQL & "AND tblStudents.Class =" & avarClasses(Me.cboClasses.ListIndex, 2) & " "
strSQL = strSQL & "ORDER BY tblClassTut.Name, Name"
strSQL2 = "SELECT tblGrades.StudentID, tblGrades.OptID, tblOptions.PrintName as Subject, tblGrades.Eff" & Me.intPeriod & " as Eff, tblGrades.Att" & Me.intPeriod & " as Att, tblOptions.AttChar, tblOptions.Order "
strSQL2 = strSQL2 & "FROM tblGrades, tblOptions "
strSQL2 = strSQL2 & "WHERE tblGrades.OptID = tblOptions.ID "
strSQL2 = strSQL2 & "ORDER BY tblOptions.Order"
strSQL = "SHAPE {" & strSQL & "} AS Student APPEND ({" & strSQL2 & "} AS Subjects RELATE ID TO StudentID) AS Subjects"
Set rstRepData = New ADODB.Recordset
rstRepData.Open strSQL, cnn.ConnectionString, adOpenStatic, adLockReadOnly
Set rep.DataSource = rstRepData
With rep.Sections("Student"
.Controls ' Group header section
' Next 3 lines work fine
.Item("txtName"
.DataField = "Name"
.Item("txtHouse"
.DataField = "House"
.Item("txtClass"
.DataField = "Class"
End With
With rep.Sections("Subjects"
.Controls ' Detail section
' Next 3 lines don't work, only if I change to -
' .Item("txtSubject"
.DataField = "Name" or "House" or "Class"
.Item("txtSubject"
.DataField = "Subject"
.Item("txtEff"
.DataField = "Eff"
.Item("txtAtt"
.DataField = "Att"
End With
rep.Show vbModal
Unload rep
Set rep = Nothing
I've created a datareport in VB6 without using the data environment. There is one grouping level, achieved using the SHAPE command. The report displays data in the correct format (group header and correct number of child records for each parent), but only works if I assign a parent column as the datafield of the child fields in the detail section. If I try to assign one of the child columns to the child field then I get the "DataField <name> not found".
Code is below, any ideas greatly appreciated.
Dim strSQL As String, strSQL2 As String
Dim rep As New rptStudGradesHT2
Dim rstRepData As ADODB.Recordset
strSQL = "SELECT tblStudents.ID, CONCAT(tblStudents.LName, ', ', tblStudents.FName) AS Name, tblHouses.Name as House, If(tblClassTut.Year<10, Right(tblClassTut.Name, 2), CONCAT(Trim(tblClassTut.Year), Left(tblHouses.Name,1))) as Class, tblClassTut.Year "
strSQL = strSQL & "FROM tblClassTut, tblHouses, tblStudents "
strSQL = strSQL & "WHERE tblClassTut.ID = tblStudents.Class AND tblHouses.ID = tblStudents.House "
strSQL = strSQL & "AND tblStudents.Class =" & avarClasses(Me.cboClasses.ListIndex, 2) & " "
strSQL = strSQL & "ORDER BY tblClassTut.Name, Name"
strSQL2 = "SELECT tblGrades.StudentID, tblGrades.OptID, tblOptions.PrintName as Subject, tblGrades.Eff" & Me.intPeriod & " as Eff, tblGrades.Att" & Me.intPeriod & " as Att, tblOptions.AttChar, tblOptions.Order "
strSQL2 = strSQL2 & "FROM tblGrades, tblOptions "
strSQL2 = strSQL2 & "WHERE tblGrades.OptID = tblOptions.ID "
strSQL2 = strSQL2 & "ORDER BY tblOptions.Order"
strSQL = "SHAPE {" & strSQL & "} AS Student APPEND ({" & strSQL2 & "} AS Subjects RELATE ID TO StudentID) AS Subjects"
Set rstRepData = New ADODB.Recordset
rstRepData.Open strSQL, cnn.ConnectionString, adOpenStatic, adLockReadOnly
Set rep.DataSource = rstRepData
With rep.Sections("Student"
' Next 3 lines work fine
.Item("txtName"
.Item("txtHouse"
.Item("txtClass"
End With
With rep.Sections("Subjects"
' Next 3 lines don't work, only if I change to -
' .Item("txtSubject"
.Item("txtSubject"
.Item("txtEff"
.Item("txtAtt"
End With
rep.Show vbModal
Unload rep
Set rep = Nothing