2012-04-24 243 views
-1

我在使用vb 6.0調用水晶報表8.5時遇到問題。我不知道如何使用VB調用該報告。這是一個例子的代碼,我有寫VB +水晶報表

Private Sub Command1_Click() 
    openConnection 

    If Me.cmbMonth = "" And Me.cmbYear = "" Then 
     MsgBox "Please select MONTH and YEAR" 
     Exit Sub 
     End If 

    Set rs = New ADODB.Recordset 
    With crp 
     .ReportFileName App.Path & "\Report\VariableReport.rpt" 
     .WindowTitle "Report" 

    End With 

End Sub 
+1

哇...... vb 6.0自從高中之後我還沒有碰過... – Michael 2012-04-24 08:12:02

回答

0
Dim tbl As CRAXDDRT.DatabaseTable 
Dim cn As New ADODB.Connection 
Dim rs As New ADODB.Recordset 
Dim m_rpt As String 

m_rpt = rs("Path") + "AnalysisCodeList2.rpt" 

crystalrpt.reportfilename = m_rpt 
crystalrpt.connect = rs("RptConnect") 

crystalrpt.ParameterFields(0) = "PrintUser;" & m_curUser & ";true" 
crystalrpt.ParameterFields(1) = "AnalysisCategory;" & CStr(Nz(cboAnalysisCategory.Value, "")) & ";true" 

If Nz(cboAccountCodeTo.Value, "") <> "" And Nz(cboAccountCodeFm.Value, "") = "" Then 
    crystalrpt.ParameterFields(2) = "AnalysisCodeRangeStart;" & CStr(Nz(cboAccountCodeFm.ItemData(0), "")) & ";true" 
    crystalrpt.ParameterFields(3) = "AnalysisCodeRangeEnd;" & CStr(Nz(cboAccountCodeTo.Value, "")) & ";true" 
Else 
    crystalrpt.ParameterFields(2) = "AnalysisCodeRangeStart;" & CStr(Nz(cboAccountCodeFm.Value, "")) & ";true" 
    crystalrpt.ParameterFields(3) = "AnalysisCodeRangeEnd;" & CStr(Nz(cboAccountCodeTo.Value, "")) & ";true" 
End If 

crystalrpt.ParameterFields(4) = "AnalysisCodeFilter;" & CStr(Replace(Nz(txtAccountCodeFilter.Value, ""), "*", "~")) & ";true" 
crystalrpt.ParameterFields(5) = "MatchCase;" & CStr(Nz(txtMatchCase.Value, "")) & ";true" 
crystalrpt.ParameterFields(6) = "Description;" & CStr(Nz(txtDescription.Value, "")) & ";true" 

crystalrpt.Action = 1 
+0

感謝Martin,但是你能否給我一點關於這個編碼的解釋。 – user692495 2012-04-24 07:05:20

0

進口CrystalDecisions.CrystalReports.Engine 昏暗RPT作爲新的ReportDocument rpt.Load(Application.StartupPath + 「\報告\ VariableReport.rpt」) rpt.SetDataSource(rs)