【发布时间】:2013-11-13 17:42:49
【问题描述】:
我正在使用 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
我想要的是创建报告,其中报告包含学生的姓名和详细信息,基于我的搜索条件,在这种情况下是班级。
【问题讨论】:
-
我不知道DataReport2是什么,但是需要将报表中的字段绑定到RS1中的字段。报告将负责读取数据。您只需设置报告控件的文本并在每次迭代时覆盖值。
-
DataReport2是Vb-6自带的报表生成工具。我知道这些字段正在被覆盖,而这正是我的问题所在。如何将“绑定”作为数据显示在“过滤”而不是“原样”的基础上。
-
在报表设计器中,在详细信息部分放置一个文本框,并将其
DataField属性设置为记录集中字段的名称。对要显示的每个字段重复此操作。 “过滤”将由您的查询处理。
标签: database ms-access vb6 report adodb