在针对VB6框架的Active report 6中,我试图基于布尔列将数据分组以显示在不同的组标题下。数据通过我在FetchData方法中初始化的记录集进入活动报告。我在激活方法中声明我的字段。 (这是我看到的在线教程的方式。)尝试将记录集列分配给访存数据方法中的字段时出现错误。 (下标超出范围。)使我相信,当我看到此信息时,我需要专门处理循环的迭代以及上下限。我对vb6不太熟悉,但是我试图在字段中贴一个“ 1”,它仍然会给出该错误,所以我必须不得不遍历字段而不是记录集吗?这是我的代码。我在详细信息部分的每个文本框的属性菜单中,将数据字段设置为对应的列名,并且我正在对此进行测试,但未填充任何内容。我在列上也设置了groupheader的数据字段,我也希望基于属性的设置,这也不起作用,这就是为什么我开始以编程方式执行此操作,因为直到运行时才设置数据源。
Private Sub ActiveReport_Activate()
Fields.Add "fldLock"
Fields.Add "fldEquipment"
Fields.Add "fldBreaker"
Fields.Add "fldPotHazEner"
Fields.Add "ValveTxt"
GroupHeader1.DataField = "ValveLS"
GroupHeader1.GroupValue = "1"
GroupHeader2.DataField = "ValveLS"
GroupHeader2.GroupValue = "0"
End Sub
Private Sub ActiveReport_FetchData(eof As Boolean)
Dim hdrrs As adodb.Recordset
BuildSql
If SQLConn.connectToDatabase Then
Set rs = SQLConn.openRS(sql, adUseClient, adOpenDynamic, adLockReadOnly)
End If
'Populate Header and Footer even if no detail records are found.
If PageHeader.Controls.item("fldSystem") = "" Then
sql = "Select * From "
sql = sql + "Lockout.dbo.LockoutSystemDB Left Outer Join "
sql = sql + "HDData.dbo.tblUsers On RevisedByLA = USLanID "
sql = sql + "Where SystemIDLA = " & SystemID & " "
If SQLConn.connectToDatabase Then
Set hdrrs = SQLConn.openRS(sql, adUseClient, adOpenDynamic, adLockReadOnly)
If Not hdrrs.eof Then
PageHeader.Controls.item("fldSystem") = hdrrs.Fields("SystemNameLA")
PageHeader.Controls.item("fldProcComment") = hdrrs.Fields("ProcCommentLA")
If hdrrs.Fields("CommentForeColor") = "Red" Then
PageHeader.Controls.item("fldProcComment").ForeColor = vbRed
Else
PageHeader.Controls.item("fldProcComment").ForeColor = vbBlack
End If
PageFooter.Controls.item("fldPrintDate") = Now() & " by " & GetLanIDName(CURRENT_USER_LANID)
PageFooter.Controls.item("fldRevisionDate") = hdrrs.Fields("RevisionDateLA") & " by " & Trim(hdrrs.Fields("USFName")) & " " & Trim(hdrrs.Fields("USLName"))
PageFooter.Controls.item("fldLocks") = hdrrs.Fields("LocksLA")
End If
hdrrs.Close
Set hdrrs = Nothing
End If
End If
If rs.eof Then Exit Sub
' If rs.Fields("ValveLS") = True Then
' GroupHeader1.Controls.item("ValveLockTxt") = rs.Fields("LockIDLS")
' GroupHeader1.Controls.item("ValveProcTxt") = rs.Fields("StepDescriptionLS")
' GroupHeader1.Controls.item("PotHazEnerValveTxt") = rs.Fields("TypePotHazEnergyLS")
' End If
If rs.Fields("LockIDLS") <> 0 Then
'Fields.item("fldLock").value = Trim(rs.Fields("LockIDLS"))
Fields("fldLock").value = Trim(rs.Fields("LockIDLS"))
'Detail.Controls.item("fldLock") = rs.Fields("LockIDLS")
Else
Fields("fldLock").value = ""
'Detail.Controls.item("fldLock") = ""
End If
Fields("fldEquipment").value = Trim(rs.Fields("StepDescriptionLS"))
Fields("ValveTxt").value = Trim(rs.Fields("ValveLS"))
'Detail.Controls.item("fldEquipment") = Trim(rs.Fields("StepDescriptionLS"))
'Detail.Controls.item("ValveTxt") = rs.Fields("ValveLS")
If Trim(rs.Fields("ForeColor")) = "Red" Then
Detail.Controls.item("fldEquipment").ForeColor = vbRed
ElseIf Trim(rs.Fields("ForeColor")) = "Blue" Then
Detail.Controls.item("fldEquipment").ForeColor = vbBlue
ElseIf Trim(rs.Fields("ForeColor")) = "Yellow" Then
Detail.Controls.item("fldEquipment").ForeColor = vbYellow
Else
Detail.Controls.item("fldEquipment").ForeColor = vbBlack
End If
Fields("fldPotHazEner").value = Trim(rs.Fields("TypePotHazEnergyLS"))
Fields("fldBreaker").value = Trim(rs.Fields("BreakerLS"))
'Detail.Controls.item("fldPotHazEner") = Trim(rs.Fields("TypePotHazEnergyLS"))
'Detail.Controls.item("fldBreaker") = Trim(rs.Fields("BreakerLS"))
rs.MoveNext
eof = False
End Sub