我正在用 VB 开发一个自动化系统,该项目处于最后阶段。我正在研究报告生成。我面临的问题是,我想创建一个基于学生班级的全年报告。无论何时生成报告,如果我使用循环,我只能看到报告记录中第一个学生的姓名或最后一个学生的姓名。
仅供参考,我将 ADODB 与 Access 数据库一起使用,并使用 ADODB.RecordSet 读取数据。
我的报告生成部分如下所示:
Set RS1 = New ADODB.recordSet
RS1.Open "SELECT * FROM RECORDS WHERE sClass = '" & ClassBox.Text & "';", connection, 3, adLockOptimistic
If Not RS1.EOF Then
Set DataReport2.DataSource = RS1.DataSource
End If
RS1.MoveFirst
Do Until RS1.EOF
DataReport2.Sections("Section1").Controls("NameLbl").Caption = CStr(RS1!sName)
DataReport2.Sections("Section1").Controls("SectionLbl").Caption = CStr(RS1!sSection)
DataReport2.Sections("Section1").Controls("ClassLbl").Caption = CStr(RS1!sClass)
DataReport2.Sections("Section1").Controls("JanLbl").Caption = CStr(RS1!January)
DataReport2.Sections("Section1").Controls("FebLbl").Caption = CStr(RS1!February)
DataReport2.Sections("Section1").Controls("MarLbl").Caption = CStr(RS1!March)
DataReport2.Sections("Section1").Controls("AprLbl").Caption = CStr(RS1!April)
DataReport2.Sections("Section1").Controls("MayLbl").Caption = CStr(RS1!May)
DataReport2.Sections("Section1").Controls("JunLbl").Caption = CStr(RS1!June)
DataReport2.Sections("Section1").Controls("JulLbl").Caption = CStr(RS1!July)
DataReport2.Sections("Section1").Controls("AugLbl").Caption = CStr(RS1!August)
DataReport2.Sections("Section1").Controls("SepLbl").Caption = CStr(RS1!September)
DataReport2.Sections("Section1").Controls("OctLbl").Caption = CStr(RS1!October)
DataReport2.Sections("Section1").Controls("NovLbl").Caption = CStr(RS1!November)
DataReport2.Sections("Section1").Controls("DecLbl").Caption = CStr(RS1!December)
DataReport2.Sections("Section1").Controls("TotalLbl").Caption = CStr(Val(RS1!January) + Val(RS1!February) + _
Val(RS1!March) + Val(RS1!April) + Val(RS1!May) + Val(RS1!June) + Val(RS1!July) + Val(RS1!August) + _
Val(RS1!September) + Val(RS1!October) + Val(RS1!November) + Val(RS1!December))
RS1.MoveNext
Loop
DataReport2.Show
我想要的是创建报告,其中报告包含学生的姓名和详细信息,基于我的搜索条件,在这种情况下是班级。