首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

VB+datareport做报表时提示:未找到DataField '空'。该怎么解决

2012-03-07 
VB+datareport做报表时提示::未找到DataField 空。我在用VB做报表时错误提示为:未找到DataField 空。代

VB+datareport做报表时提示::未找到DataField '空'。
我在用VB做报表时错误提示为:未找到DataField '空'。 
  代码如下: 
  Option Explicit 

Private Sub DataReport_Initialize() 
'设置报表宽度 
'DataReport2.ReportWidth = Printer.Width - DataReport2.LeftMargin - DataReport2.RightMargin 
  Dim cn As ADODB.Connection 
  Dim rs As ADODB.Recordset 
  Dim sql As String, strSQL, test As String 
  Dim gID As Integer, i As Integer 
   
  '连接数据库,打开记录集 
  Set cn = New ADODB.Connection 
  Set rs = New ADODB.Recordset 
   
   
  cn.Provider = "MSDataShape" '一定要这句,因为要用到ADO的SHAPE命令 
  cn.Open "Data Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "/蚕种检疫.mdb;Persist Security Info=False" 
  rs.CursorLocation = adUseClient 
  '设置数据集游标类型和锁定类型(可更新类型) 
  rs.CursorLocation = adUseClient 
  rs.LockType = adLockOptimistic 
  rs.ActiveConnection = cn 
   
   
   
  '用SHAPE命令打开分组父子记录集 
  sql = "select * FROM 查询结果" 
  strSQL = "SHAPE {" & sql & " } " & _ 
  "AS mGroup COMPUTE sum(mGroup.编码) as piece,mGroup BY '编码'" 
  Set rs = New ADODB.Recordset 
  rs.Open strSQL, cn, adOpenStatic, adLockReadOnly 
  test = rs.Fields("编码") 
  MsgBox test 
  '设置报表数据源 
  Set DataReport2.DataSource = rs 
  MsgBox rs.RecordCount 
  '设置报表控件属性 
  '分组标头,不用设置DataMember 
  DataReport2.Sections("Section6").Controls("Text16").DataField = "编码" 
  DataReport2.Sections("Section6").Controls("Text16").Visible = False '隐藏分组信息 
  DataReport2.Sections("Section6").ForcePageBreak = 1 '强制分页 
  '细节标头 
  DataReport2.Sections("Section1").Controls("Text1").DataMember = "mGroup" 
  DataReport2.Sections("Section1").Controls("Text1").DataField = "制种组别" 
  DataReport2.Sections("Section1").Controls("Text2").DataMember = "mGroup" 
  DataReport2.Sections("Section1").Controls("Text2").DataField = "品种名称" 
  DataReport2.Sections("Section1").Controls("Text3").DataMember = "mGroup" 
  DataReport2.Sections("Section1").Controls("Text3").DataField = "用种季别" 
  DataReport2.Sections("Section1").Controls("Text4").DataMember = "mGroup" 
  DataReport2.Sections("Section1").Controls("Text4").DataField = "制毛种张数" 
  DataReport2.Sections("Section1").Controls("Text5").DataMember = "mGroup" 
  DataReport2.Sections("Section1").Controls("Text5").DataField = "应检盒数" 
  DataReport2.Sections("Section1").Controls("Text6").DataMember = "mGroup" 
  DataReport2.Sections("Section1").Controls("Text6").DataField = "实检盒数" 
  DataReport2.Sections("Section1").Controls("Text7").DataMember = "mGroup" 
  DataReport2.Sections("Section1").Controls("Text7").DataField = "产卵日期" 


  DataReport2.Sections("Section1").Controls("Text8").DataMember = "mGroup" 
  DataReport2.Sections("Section1").Controls("Text8").DataField = "抽检n1盒数" 
  DataReport2.Sections("Section1").Controls("Text9").DataMember = "mGroup" 
  DataReport2.Sections("Section1").Controls("Text9").DataField = "抽检n2盒数" 
  DataReport2.Sections("Section1").Controls("Text10").DataMember = "mGroup" 
  DataReport2.Sections("Section1").Controls("Text10").DataField = "抽检数合计" 
  DataReport2.Sections("Section1").Controls("Text11").DataMember = "mGroup" 
  DataReport2.Sections("Section1").Controls("Text11").DataField = "n1病蛾数" 
  DataReport2.Sections("Section1").Controls("Text12").DataMember = "mGroup" 
  DataReport2.Sections("Section1").Controls("Text12").DataField = "n2病蛾数" 
  DataReport2.Sections("Section1").Controls("Text13").DataMember = "mGroup" 
  DataReport2.Sections("Section1").Controls("Text13").DataField = "病蛾数合计" 
  DataReport2.Sections("Section1").Controls("Text14").DataMember = "mGroup" 
  DataReport2.Sections("Section1").Controls("Text14").DataField = "允许病蛾数" 
  DataReport2.Sections("Section1").Controls("Text15").DataMember = "mGroup" 
  DataReport2.Sections("Section1").Controls("Text15").DataField = "合格判定" 
   
  '分组注脚,页合计。不用设置DataMember 
  DataReport2.Sections("Section7").Controls("Label5").Caption = "注:合格判定:合格或淘汰" 
  DataReport2.Sections("Section7").Controls("Label6").Caption = "检疫单位签字(盖章)" 
  DataReport2.Sections("Section7").Controls("label7").Caption = "检疫员签字:" 
  DataReport2.Sections("Section7").Controls("Label8").Caption = "填报如期 月 日" 
  '页标头,不要每页显示的话也可以放在报表标头中 
  DataReport2.Sections("Section2").Controls("Label1").Caption = "家蚕一代杂交种母蛾检验报告(代检验证书)" 
  DataReport2.Sections("Section2").Controls("Label2").Caption = " 场名:" & coding 
  DataReport2.Sections("Section2").Controls("Label3").Caption = " " & Year(Date) & "年" 
  DataReport2.Sections("Section2").Controls("Label4").Caption = "制种季别:" 
  End Sub 
  datareport里面就16个textbox控件,每个都有给值。忘高手帮忙解决下。

[解决办法]
极有可能有多余的有datafield属性的控件,你在报表属性窗口中上方的下拉框中找一下
还有SQL语句指定字段名称,比如:
select 品种名称,.... from tb
这样绑定控件:
DataReport2.Sections("Section1").Controls("Text2").DataField = rs.fields("品种名称").name
 


热点排行