Option Explicit dim Report as New Cystal1 Private Sub Form_Load() Screen.MousePointer = vbHourglass '调用水晶报表时置鼠标为沙漏状 CRViewer91.ReportSource = Report '该语句的赋值将在后面被修改 CRViewer91.ViewReport Screen.MousePointer = vbDefault '调用水晶报表完成后置鼠标为默认形状 End Sub Private Sub Form_Resize() CRViewer91.Top = 0 CRViewer91.Left = 0 CRViewer91.Height = ScaleHeight CRViewer91.Width = ScaleWidth End Sub |
Public conn As New ADODB.Connection Public rs As New ADODB.Recordset |
Private Sub Command1_Click() Dim connstr As String If conn.State = adStateOpen Then conn.Close connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\prtest.mdb;Persist Security Info=False" 'prtest.mdb是程序当前目录的测试Access数据库 conn.ConnectionString = connstr conn.Open conn.CursorLocation = adUseClient If rs.State = adStateOpen Then rs.Close rs.Open "test", conn, adOpenKeyset, adLockReadOnly ' Report.Database.SetDataSource rs, 3, 1 Form2.Show 1 '数据库连接完成后,调用Form2水晶报表工程 End Sub |
Option Explicit 'dim Report as New Cystal1 '上面一行取消 Private Sub Form_Load() Dim oApp As New CRAXDRT.Application Dim oRpt As CRAXDRT.Report Dim reportName As String '上面三行是新增加的 Screen.MousePointer = vbHourglass reportName = "\rpt\Pr1.rpt" '定义要引用的rpt文件 Set oRpt = oApp.OpenReport(App.Path & reportName, 1) oRpt.Database.SetDataSource rs '连接水晶报表和数据源 oRpt.ReadRecords CRViewer91.ReportSource = oRpt '启用水晶报表的预览功能 CRViewer91.ViewReport Screen.MousePointer = vbDefault End Sub Private Sub Form_Resize() CRViewer91.Top = 0 CRViewer91.Left = 0 CRViewer91.Height = ScaleHeight CRViewer91.Width = ScaleWidth End Sub Private Sub Form_Unload(Cancel As Integer) 'Set Report = Nothing Set rs = Nothing Set conn = Nothing Unload Form2 End Sub |