在vb6中连接⽔晶报表使⽤⼼得
在vb6中连接⽔晶报表使⽤⼼得
VB6中使⽤⽔晶报表并动态设置数据源
⾸先引⽤Crystal Reports 9 ActiveX Designer Run Time Library再添加Crystal Repotr View Control 9控件在⼯程资源管理器中右键--添加--Crystal Reports 9 新建⼀个Crystal Reports9报表设置数据源后将要显⽰的字段加⼊报表内。
窗体代码部分:
Dim m_Report As New CrystalReport1 '(这个CrystalReport1是你建⽴的报表的名称)
Dim m_Connection As ADODB.Connection '(建⽴⼀个ADO连接)
Dim adoRS As ADODB.Recordset
Private Sub Form_Load()
Dim SQL As String
Dim strConnect As String
' Create and bind the ADO Recordset object
Set m_Connection = New ADODB.Connection
Set adoRS = New ADODB.Recordset
' Open the connection
strConnect = "你的数据库连接字符串"
connect下载m_Connection.Open strConnect
SQL = "查询语句"
adoRS.Open SQL, m_Connection, adOpenDynamic, adLockBatchOptimistic
m_Report.Database.SetDataSource adoRS'(动态设置报表数据源)
Screen.MousePointer = vbHourglass
CRViewer1.ReportSource = m_Report
CRViewer1.ViewReport '(显⽰报表)
Screen.MousePointer = vbDefault
End Sub
显⽰打印机设置动话框
报表名.PrinterSetup Me.hWnd
⽤代码设置纸张⼤⼩
报表名.PaperSize =crPaperA4
是否显⽰右上⾓⽔晶报表的图标
CRViewer1.EnableAnimationCtrl = Not CRViewer1.EnableAnimationCtrl
是否显⽰导出报表按钮
CRViewer1.EnableExportButton = Not CRViewer1.EnableExportButton
是否显⽰关闭按钮
CRViewer1.EnableCloseButton = Not CRViewer1.EnableCloseButton
是否显⽰左侧树列表
CRViewer1.EnableGroupTree = Not CRViewer1.EnableGroupTree
是否显⽰导航
CRViewer1.EnableNavigationControls = Not CRViewer1.EnableNavigationControls
是否显⽰弹出菜单
CRViewer1.EnablePopupMenu = Not CRViewer1.EnablePopupMenu
是否显⽰打印按钮
CRViewer1.EnablePrintButton = Not CRViewer1.EnablePrintButton
是否显⽰刷新按钮
CRViewer1.EnableRefreshButton = Not CRViewer1.EnableRefreshButton
是否显⽰⼯具栏
CRViewer1.EnableToolbar = Not CRViewer1.EnableToolbar
是否显⽰⽐例调整窗⼝
CRViewer1.EnableZoomControl = Not CRViewer1.EnableZoomControl
报表显⽰的样式
CRViewer1.DisplayBackgroundEdge = Not CRViewer1.DisplayBackgroundEdge
报表控件是否有边框
CRViewer1.DisplayBorder = Not CRViewer1.DisplayBorder
是否显⽰报表的选项卡
CRViewer1.DisplayTabs = Not CRViewer1.DisplayTabs
vb中调⽤⽔晶报表⽣成的*.rpt⽂件
CrystalReport1.ReportFileName = App.Path & "liuhan.rpt" CrystalReport1.WindowTitle = "打印预览"
CrystalReport1.WindowState = crptMaximized '使打印预览窗⼝最⼤化******** CrystalReport1.Destination = crptToWindow '到窗⼝***********************
'CrystalReport1.Destination = crptToPrinter
'到打印机********************
CrystalReport1.PrinterDriver = 1
CrystalReport1.PrintReport
解决⽔晶报表更新数据后需按刷新问题报表名.DiscardSavedData
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论