VB6中的Crystal报表在首次运行时显示为空

VB6中的Crystal报表在首次运行时显示为空,vb6,crystal-reports,Vb6,Crystal Reports,所以我对Crystal Reports有一个问题,第一次尝试运行报告时,报告显示为空。报告显示了各种分隔符、行、框等,但报告中没有要填写的数据。我使用VisualBasic6进行编码。我使用了很多继承的代码,处理实际Crystal报表的代码是一个用于其他报表的文件,它工作正常。所以我确信问题在于我把事情搞砸了 以下是我目前掌握的代码: Dim rs As ADODB.Recordset Dim strRptFilePathTemp As String Dim strRptFileName As

所以我对Crystal Reports有一个问题,第一次尝试运行报告时,报告显示为空。报告显示了各种分隔符、行、框等,但报告中没有要填写的数据。我使用VisualBasic6进行编码。我使用了很多继承的代码,处理实际Crystal报表的代码是一个用于其他报表的文件,它工作正常。所以我确信问题在于我把事情搞砸了

以下是我目前掌握的代码:

Dim rs As ADODB.Recordset
Dim strRptFilePathTemp As String
Dim strRptFileName As String
Dim cSql As String

cSql = "SELECT * FROM TABLE1"

Set rs = DbConn.runStatement(cSql, "rs call", , , , , , , , , , True)  'gets a recordset based on the sql statement above

On Error GoTo ErrHandler


strRptFileName = "ReportName.rpt"

strRptFilePathTemp = App.Path


Screen.MousePointer = vbHourglass

Set frmcrystalreport.ReportRS = rs

DoEvents


frmcrystalreport.reportfile = strRptFilePathTemp & strRptFileName
frmcrystalreport.ReportTitle = _
frmCrystalReportsMainForm.GetRptTitle1("ReportTitle, ") & vbCrLf
gblStrReportFileNameLastRun = frmcrystalreport.reportfile
Screen.MousePointer = vbDefault

DoEvents

frmcrystalreport.Show vbModal

If Not frmcrystalreport.ReportRS Is Nothing Then
frmcrystalreport.ReportRS.Close
Set frmcrystalreport.ReportRS = Nothing
End If
Exit Sub

End If

End Sub

我尝试过使用DoEvents函数,看看它是否有帮助,但运气不太好。在初次尝试运行报告失败后,一切正常。只要我不退出程序,一旦我通过了那个空白报告,它就会打印出一份包含有效数据的报告。谢谢你们能给我的任何帮助。

嗯,我已经有一段时间没有使用VB6和CR了,但我记得在设置查看器报告源之前,您需要放弃保存的数据

Report.DiscardSavedData
CRViewer1.ReportSource = Report

在Crystal Reports中偶然发现一些东西后,我才发现问题所在。我必须关闭“文件”菜单下报告文件中的“使用报告保存数据”功能