我使用CR XI创建图表报告。当我尝试使用带有此代码的Crystal Report Viewer从vb6运行它时,效果很好:
Public Function prnView(ByVal rptPath As String, ByVal tblName As String, ByVal whereCondition As String, _
Optional paramPeriod As String = "", Optional sParam As String) As Boolean
Dim vApp As New CRAXDRT.Application
Dim vRpt As New CRAXDRT.Report
Dim arTbl() As String
Dim i As Integer, j As Integer
Screen.MousePointer = vbHourglass
Set vRpt = vApp.OpenReport(rptPath)
With vRpt
.DiscardSavedData
arTbl = Split(tblName, "|")
Dim ConnectionInfo As CRAXDRT.ConnectionProperties
For i = 0 To .Database.Tables.Count - 1
Set ConnectionInfo = .Database.Tables(i + 1).ConnectionProperties
.Database.Tables(i + 1).ConnectionProperties.Item("Connection String") = "DRIVER={mySQL ODBC 5.1 Driver};UID=" & defUser & ";PWD=" & defPass & ";Server=" & serverName & ";port=" & defPort & ";Database=" & defDB
.Database.Tables(i + 1).ConnectionProperties.Item("User ID") = defUser '"ztech"
.Database.Tables(i + 1).ConnectionProperties.Item("Server") = serverName ' "192.168.1.253"
.Database.Tables(i + 1).ConnectionProperties.Item("Database") = defDB 'vDB ' "192.168.1.253"
.Database.Tables(i + 1).ConnectionProperties.Item("Use DSN Default Properties") = "False"
Next
.ParameterFields(1).ClearCurrentValueAndRange
.ParameterFields(2).ClearCurrentValueAndRange
.ParameterFields(1).AddCurrentValue dtpFrom.Year
.ParameterFields(2).AddCurrentValue locSearchID
' If .ParameterFields.Count > 0 Then
' arTbl = Split(sParam, "|")
' For j = 1 To .ParameterFields.Count
' .ParameterFields(j).ClearCurrentValueAndRange
' If .ParameterFields(j).ValueType = crNumberField Then
' .ParameterFields(j).AddCurrentValue CInt(arTbl(j - 1))
' ElseIf .ParameterFields(j).ValueType = crStringField Then
' .ParameterFields(j).AddCurrentValue arTbl(j - 1)
' End If
' Next
' End If
If paramPeriod <> "" Then
For i = 1 To .Sections.Count
For j = 1 To .Sections(i).ReportObjects.Count
If .Sections(i).ReportObjects(j).Name = "strPeriod" Then
.Sections(i).ReportObjects("strPeriod").SetText paramPeriod
End If
Next
Next
End If
End With
crView.ReportSource = vRpt
crView.EnableGroupTree = False
crView.Refresh
crView.ViewReport
Screen.MousePointer = vbDefault
Set vApp = Nothing
Set vRpt = Nothing
End Function
现在的问题是,当我试图“停止”我的项目使其始终挂起,然后VB6 IDE变为“无响应”时,如果我不打开图表报告,我可以“停止”我的项目。
这是我的项目参考,以防我错过了一些在vb6中运行CR图表报告的参考: