先在VB里增加组件:CRYSTAL REPORT VIEWER CONTROR9Function ReportPrint(byval ReportName as string,byval Action as intger) Dim m_Application As CRAXDDRT.Application '报表应用对象 Dim m_Report As CRAXDDRT.Report Dim m_Rshead As New ADODB.Recordset Dim m_Rs As New ADODB.Recordset '主单 Dim m_Rs2 As New ADODB.Recordset '明细 Dim m_Rs3 As New ADODB.Recordset Set m_Application = New Application Set m_Report = New Report Set m_Report = m_Application.OpenReport(ReportName) m_Report.DiscardSavedData For i = 1 To m_Report.Database.Tables.Count TabName = UCase(m_Report.Database.Tables(i).Name) Select Case TabName Case UCase("Vw_Print_Head"),... strSQL="select * from " & TabName & " where .... " Set Rshead = g_Conn.Execute(strSQL) m_Report.Database.Tables(i).SetDataSource m_Rshead case UCase("Vw_Print_Head"),... strSQL="select * from " & TabName & " where .... " Set m_Rs = g_Conn.Execute(strSQL) m_Report.Database.Tables(i).SetDataSource m_Rs End Select Next Select Case Action Case 1 '直接打印 m_Report.PrintOut False, 1, False Case 2 '选择打印 m_Report.PrinterSetup Me.hWnd m_Report.PrintOut True Case 3 '文件导出 m_Report.Export Case 4 'Email m_Report.ExportOptions.FormatType = crEFTWordForWindows m_Report.ExportOptions.WORDWExportAllPages = True m_Report.ExportOptions.DestinationType = crEDTDiskFile m_Report.ExportOptions.DiskFileName = ExReportName m_Report.Export False
End Select If Not (m_Application Is Nothing) Then Set m_Application = Nothing End If If Not (m_Report Is Nothing) Then Set m_Report = Nothing End If end function
怎么调用报表文件?是不是一定要有设计窗体?
CRViewer91.ReportSource = app.path & "\report.rtp"会出错啊
哪能像你这么用
还有当你作完一个报表后,以后的报表可以像word.execle哪样在文件里添加一个就可以,相当于模板了
哪能像你这么用
还有当你作完一个报表后,以后的报表可以像word.execle哪样在文件里添加一个就可以,相当于模板了
Dim m_Application As CRAXDDRT.Application '报表应用对象
Dim m_Report As CRAXDDRT.Report
Dim m_Rshead As New ADODB.Recordset
Dim m_Rs As New ADODB.Recordset '主单
Dim m_Rs2 As New ADODB.Recordset '明细
Dim m_Rs3 As New ADODB.Recordset
Set m_Application = New Application
Set m_Report = New Report
Set m_Report = m_Application.OpenReport(ReportName)
m_Report.DiscardSavedData
For i = 1 To m_Report.Database.Tables.Count
TabName = UCase(m_Report.Database.Tables(i).Name)
Select Case TabName
Case UCase("Vw_Print_Head"),...
strSQL="select * from " & TabName & " where .... "
Set Rshead = g_Conn.Execute(strSQL)
m_Report.Database.Tables(i).SetDataSource m_Rshead
case UCase("Vw_Print_Head"),...
strSQL="select * from " & TabName & " where .... "
Set m_Rs = g_Conn.Execute(strSQL)
m_Report.Database.Tables(i).SetDataSource m_Rs
End Select
Next
Select Case Action
Case 1 '直接打印
m_Report.PrintOut False, 1, False
Case 2 '选择打印
m_Report.PrinterSetup Me.hWnd
m_Report.PrintOut True
Case 3 '文件导出
m_Report.Export
Case 4 'Email
m_Report.ExportOptions.FormatType = crEFTWordForWindows
m_Report.ExportOptions.WORDWExportAllPages = True
m_Report.ExportOptions.DestinationType = crEDTDiskFile
m_Report.ExportOptions.DiskFileName = ExReportName
m_Report.Export False
End Select
If Not (m_Application Is Nothing) Then
Set m_Application = Nothing
End If
If Not (m_Report Is Nothing) Then
Set m_Report = Nothing
End If
end function