使用水晶报表时,第一次可以打印没有问题,更改数据源后,第二次打印内容不更新,还是第一次的内容.
我的代码如下:
  Dim oApp As New CRAXDRT.Application
  Dim oRpt As CRAXDRT.Report
  Dim reportName As String
  '上面三行是新增加的
   
  Screen.MousePointer = vbHourglass
  '定义要引用的rpt文件
      
    CryRpt1.Database.SetDataSource PubRs
    CryRpt1.ReadRecords
    CRViewer91.ReportSource = CryRpt1    '启用水晶报表的预览功能
       
'
  CRViewer91.ViewReport
  CRViewer91.Zoom (2)
  
  Screen.MousePointer = vbDefault
    Set PubRs = Nothing
    我每次打印时,更改Pubrs
但是:CRViewer91.ViewReport 并没有刷新.
急用,谢谢

解决方案 »

  1.   

    请楼主看看我的例子,打印打印记录源CrystalReport1设计器左上角选:数据字段—数据专家—创建新连接-OLEDB(ADO)自己设置一下数据库—把command选到表里—编辑command—把SQL语句写在左边的框里(不要加数据库以外的,在底下代码里加),然后把command里的字段拖到设计器上。打印窗体里:‘声明
    Dim m_Report As New CrystalReport1 ’你的设计器Dim m_Connection As ADODB.Connection
    Dim adoRS As ADODB.Recordset
    Option ExplicitPrivate Sub Form_Load()
       On Error Resume Next
      Dim sql As String
        Dim strConnect As String
       
        ' Create and bind the ADO Recordset object
        Set m_Connection = New ADODB.Connection
        Set adoRS = New ADODB.Recordset    ' Open the connection
        strConnect = JetOLEDB ’你的连接串
        m_Connection.Open strConnectsql = "select Instore.ProId as 产品编号,ProName as 产品名称,Quantity as 数量,Hand as 经手人,InstoreCode as 票号,Instore.Indate as 日期 From Instore Join  Product on dbo.Instore.ProId=dbo.Product.ProId where Instore.Indate between '" + Str(FrmInstoreQuery.DTP1.Value) + "' and '" + Str(FrmInstoreQuery.DTP2.Value) + "' and  " & b & " = '" + FrmInstoreQuery.Text1.Text + " '"
        
          adoRS.Open sql, m_Connection, adOpenDynamic, adLockBatchOptimistic ‘这里是打印的记录源
        m_Report.Database.SetDataSource adoRS
        
        Screen.MousePointer = vbHourglass
        CRViewer1.ReportSource = m_Report
        CRViewer1.ViewReport
        Screen.MousePointer = vbDefault
    End SubPrivate Sub Form_Resize()
    CRViewer1.Top = 0
    CRViewer1.Left = 0
    CRViewer1.Height = ScaleHeight
    CRViewer1.Width = ScaleWidth
    End Sub       End If
      

  2.   

    我的PubRs是一个全局变量,从别的窗体中穿过来的记录源
      

  3.   

    试试:Dim oApp As New CRAXDRT.Application
      Dim oRpt As CRAXDRT.Report
      Dim reportName As String
      '上面三行是新增加的
       
      Screen.MousePointer = vbHourglass
      '定义要引用的rpt文件
          
        '清除报表中保持的数据
        CryRpt1.DiscardSavedData  '<-------------------加上这句后再试试
        '赋给报表数据
        CryRpt1.Database.SetDataSource PubRs
        CryRpt1.ReadRecords
        CRViewer91.ReportSource = CryRpt1    '启用水晶报表的预览功能
           
    '
      CRViewer91.ViewReport
      CRViewer91.Zoom (2)
      
      Screen.MousePointer = vbDefault
        Set PubRs = Nothing