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

關於VB中使用水晶報表的問題,该如何处理

2012-03-30 
關於VB中使用水晶報表的問題DimfldAsFieldObjectDimstrCnnAsStringSetcnn1NewADODB.ConnectionstrCnnPr

關於VB中使用水晶報表的問題
Dim   fld   As   FieldObject
        Dim   strCnn   As   String
       
                Set   cnn1   =   New   ADODB.Connection
          strCnn   =   "Provider=SQLOLEDB.1;Password=sa;User   ID=sa;initial   catalog=mesdbchtorg;data   source=cmq "
            cnn1.Open   strCnn

              Set   datcmd1   =   New   ADODB.Command
        Set   datcmd1.ActiveConnection   =   cnn1
        datcmd1.CommandText   =   "lot "
        datcmd1.CommandType   =   adCmdTable

              Set   fld   =   m_Report.Section3.AddFieldObject( "{ado.lot   lotnm} ",   0,   0)
上面這一句中會出錯。不知AddFieldObject( "{ado.lot   lotnm} ",   0,   0)的第一個參數該添什麼?
thanks


[解决办法]
以前写过的一段代码,现在机器上无报表,所以只能给你代码看看,仅参考
我这个是子表表比较复杂,你写单表会简单很多

Private Sub Form_Load()
Dim i As Integer
Dim oConn As New ADODB.Connection
Dim rst1 As New ADODB.Recordset
Dim rst2 As New ADODB.Recordset
Dim rst3 As New ADODB.Recordset
Dim Obj As Object
Dim props As CRAXDRT.ConnectionProperties '报表数据源参数集
Dim prop As CRAXDRT.ConnectionProperty '报表数据源参数
Dim oSection As CRAXDRT.Section '报表节对象
Dim CRXSubReport As CRAXDRT.SubreportObject '子报表对象
Dim CRXSubReportTemp As CRAXDRT.Report '子报表
Dim bSubreport As Boolean

rst1.CursorLocation = adUseClient
rst2.CursorLocation = adUseClient
rst3.CursorLocation = adUseClient
'获取数据
oConn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE= " & App.Path & "\test.mdb; "
Set rst1 = oConn.Execute( "Select * From Student ")
Set rst2 = oConn.Execute( "Select * From Book ")
Set rst3 = oConn.Execute( "Select * From Class ")


'--------------------------------------------------
'创建报表
'--------------------------------------------------
'加载报表模板
Set objCRReport = objCRApp.OpenReport(App.Path & "\ReportMain.rpt ", 1)

'加载主报表字段定义文件
Set props = objCRReport.Database.Tables(1).ConnectionProperties
For Each prop In props
If InStr(prop.Name, "Field Definition File ") > 0 Then
prop.Value = App.Path & "\Students.ttx "
Exit For
End If
Next
Set props = Nothing
'给主报表赋值
objCRReport.DiscardSavedData
objCRReport.Database.Tables(1).SetDataSource rst1

'第一个子报表
bSubreport = False
'循环报表的每个节
For Each oSection In objCRReport.Sections
'循环该节中的每个报表对象
For Each Obj In oSection.ReportObjects
'如果该报表对象是子报表
If Obj.Kind = crSubreportObject Then
'如果是第一个子报表,根据名称匹配,注意大小写有区别的
'获取这个报表对象,跳出循环,准备操作
If LCase(Obj.Name) = "subreport1 " Then
Set CRXSubReport = Obj
bSubreport = True
End If
Exit For


End If
Next Obj
If bSubreport Then Exit For
Next oSection
'设定该版子报表的ttx
Set CRXSubReportTemp = CRXSubReport.OpenSubreport
Set props = CRXSubReportTemp.Database.Tables(1).ConnectionProperties

For Each prop In props
If InStr(prop.Name, "Field Definition File ") > 0 Then
'设置子报表的字段定义文件(TTX)
prop.Value = App.Path & "\books.ttx "
Exit For
End If
Next
'数据填充
CRXSubReportTemp.DiscardSavedData
CRXSubReportTemp.Database.Tables(1).SetDataSource rst2
Set props = Nothing
Set prop = Nothing
'第2个子报表
bSubreport = False
For Each oSection In objCRReport.Sections
For Each Obj In oSection.ReportObjects
If Obj.Kind = crSubreportObject Then
If LCase(Obj.Name) = "subreport2 " Then
Set CRXSubReport = Obj
bSubreport = True
End If
Exit For
End If
Next Obj
If bSubreport Then Exit For
Next oSection

Set CRXSubReportTemp = CRXSubReport.OpenSubreport
Set props = CRXSubReportTemp.Database.Tables(1).ConnectionProperties

For Each prop In props
If InStr(prop.Name, "Field Definition File ") > 0 Then
'ZMQ设置子报表的字段定义文件(TTX)
prop.Value = App.Path & "\classes.ttx "
Exit For
End If
Next
CRXSubReportTemp.DiscardSavedData
CRXSubReportTemp.Database.Tables(1).SetDataSource rst3
Set props = Nothing
Set prop = Nothing


objCRReport.EnableParameterPrompting = False '不进行报表参数提示

'--------------------------------------------------

'--------------------------------------------------
'进行报表显示外观设置
'--------------------------------------------------

objCRReport.LeftMargin = 10
objCRReport.RightMargin = 10
CRViewer91.EnableExportButton = True '导出按钮
CRViewer91.EnableSelectExpertButton = False
CRViewer91.DisplayGroupTree = False '不显示组树
CRViewer91.EnableAnimationCtrl = False
CRViewer91.EnableCloseButton = False
CRViewer91.EnableGroupTree = False
CRViewer91.EnableHelpButton = False
CRViewer91.EnableRefreshButton = False
CRViewer91.EnableNavigationControls = True
CRViewer91.EnablePopupMenu = False
CRViewer91.EnableSearchControl = False
CRViewer91.EnableSearchExpertButton = False
CRViewer91.EnableSelectExpertButton = False
CRViewer91.DisplayTabs = False


'指定报表来源
CRViewer91.ReportSource = objCRReport
'显示报表
CRViewer91.ViewReport

Set rst1 = Nothing
Set rst2 = Nothing
End Sub

热点排行