首页上一页 1 下一页尾页 2 条记录 1/1页
打印
发表在VB答疑区
2008-09-18
是否精华
是
否
版块置顶:
是
否
在通过datareport对象打印时出现"未找到datafield'2008-4-5'"错误提示????请帮忙看看以下是代码:
Private Sub DataReport_Initialize()
Dim str1 As String
Const iW = 3 '缇,误差调整
Printer.PaperSize = 9
DaReportjrdy.ReportWidth = Printer.Width - DaReportjrdy.LeftMargin - DaReportjrdy.RightMargin - iW
Dim AdoRec As New ADODB.Recordset
Dim txt As New Collection
Dim ctl As Object
Dim ctl1 As Object
str1 = "SELECT a1, a2, a3,a11,a4 ,a5,a6,a7,a8,a9,a10,b1,sum(a10) as b2 FROM view_jr where a1>='" & starttime & "' and a1<='" & endtime & "'and a12='" & UserDept & "'group by a1, a2, a3,a4 ,a5,a6,a7,a8,a9,a10,b1,a11 "
AdoRec.Open str1, AdoCon
Set DaReportjrdy.DataSource = AdoRec
'动态设置报表中各数据控件的绑定字段
For Each ctl In Me.Sections.Item("Section1").Controls
If TypeName(ctl) = "RptTextBox" Then
Select Case ctl.Name
Case "Text1"
If IsNull(AdoRec.Fields("a1")) = True Then
ctl.DataField = ""
Else
ctl.DataField = AdoRec.Fields("a1").Value
End If
Case "Text2"
If IsNull(AdoRec.Fields("a11")) = True Then
ctl.DataField = ""
Else
ctl.DataField = AdoRec.Fields("a11").Value
End If
Case "Text3"
If IsNull(AdoRec.Fields("a3")) = True Then
ctl.DataField = ""
Else
ctl.DataField = AdoRec.Fields("a3").Value
End If
Case "Text4"
If IsNull(AdoRec.Fields("a4")) = True Then
ctl.DataField = ""
Else
ctl.DataField = AdoRec.Fields("a4").Value
End If
Case "Text5"
If IsNull(AdoRec.Fields("a5")) = True Then
ctl.DataField = ""
Else
ctl.DataField = AdoRec.Fields("a5").Value
End If
Case "Text6"
If IsNull(AdoRec.Fields("a6")) = True Then
ctl.DataField = ""
Else
ctl.DataField = AdoRec.Fields("a6").Value
End If
Case "Text7"
If IsNull(AdoRec.Fields("a7")) = True Then
ctl.DataField = ""
Else
ctl.DataField = AdoRec.Fields("a7").Value
End If
Case "Text8"
If IsNull(AdoRec.Fields("a8")) = True Then
ctl.DataField = ""
Else
ctl.DataField = AdoRec.Fields("a8").Value
End If
Case "Text9"
If IsNull(AdoRec.Fields("a9")) = True Then
ctl.DataField = ""
Else
ctl.DataField = AdoRec.Fields("a9").Value
End If
Case "Text10"
If IsNull(AdoRec.Fields("a10")) = True Then
ctl.DataField = ""
Else
ctl.DataField = AdoRec.Fields("a10").Value
End If
Case "Text13"
ctl.DataField = AdoRec.Fields("b1").Value
End Select
End If
Next
End Sub
Private Sub DataReport_Initialize()
Dim str1 As String
Const iW = 3 '缇,误差调整
Printer.PaperSize = 9
DaReportjrdy.ReportWidth = Printer.Width - DaReportjrdy.LeftMargin - DaReportjrdy.RightMargin - iW
Dim AdoRec As New ADODB.Recordset
Dim txt As New Collection
Dim ctl As Object
Dim ctl1 As Object
str1 = "SELECT a1, a2, a3,a11,a4 ,a5,a6,a7,a8,a9,a10,b1,sum(a10) as b2 FROM view_jr where a1>='" & starttime & "' and a1<='" & endtime & "'and a12='" & UserDept & "'group by a1, a2, a3,a4 ,a5,a6,a7,a8,a9,a10,b1,a11 "
AdoRec.Open str1, AdoCon
Set DaReportjrdy.DataSource = AdoRec
'动态设置报表中各数据控件的绑定字段
For Each ctl In Me.Sections.Item("Section1").Controls
If TypeName(ctl) = "RptTextBox" Then
Select Case ctl.Name
Case "Text1"
If IsNull(AdoRec.Fields("a1")) = True Then
ctl.DataField = ""
Else
ctl.DataField = AdoRec.Fields("a1").Value
End If
Case "Text2"
If IsNull(AdoRec.Fields("a11")) = True Then
ctl.DataField = ""
Else
ctl.DataField = AdoRec.Fields("a11").Value
End If
Case "Text3"
If IsNull(AdoRec.Fields("a3")) = True Then
ctl.DataField = ""
Else
ctl.DataField = AdoRec.Fields("a3").Value
End If
Case "Text4"
If IsNull(AdoRec.Fields("a4")) = True Then
ctl.DataField = ""
Else
ctl.DataField = AdoRec.Fields("a4").Value
End If
Case "Text5"
If IsNull(AdoRec.Fields("a5")) = True Then
ctl.DataField = ""
Else
ctl.DataField = AdoRec.Fields("a5").Value
End If
Case "Text6"
If IsNull(AdoRec.Fields("a6")) = True Then
ctl.DataField = ""
Else
ctl.DataField = AdoRec.Fields("a6").Value
End If
Case "Text7"
If IsNull(AdoRec.Fields("a7")) = True Then
ctl.DataField = ""
Else
ctl.DataField = AdoRec.Fields("a7").Value
End If
Case "Text8"
If IsNull(AdoRec.Fields("a8")) = True Then
ctl.DataField = ""
Else
ctl.DataField = AdoRec.Fields("a8").Value
End If
Case "Text9"
If IsNull(AdoRec.Fields("a9")) = True Then
ctl.DataField = ""
Else
ctl.DataField = AdoRec.Fields("a9").Value
End If
Case "Text10"
If IsNull(AdoRec.Fields("a10")) = True Then
ctl.DataField = ""
Else
ctl.DataField = AdoRec.Fields("a10").Value
End If
Case "Text13"
ctl.DataField = AdoRec.Fields("b1").Value
End Select
End If
Next
End Sub