已经做好了的水晶报表文件,该如何在VB中调用呢? 如何实现打印和预览? 小弟对此不大熟悉,恳请高人指教,谢谢!!

解决方案 »

  1.   

    Option ExplicitDim m_Report As New CrystalReport1' The ADO connection to the local database.
    Dim cnn1 As ADODB.Connection
    Dim datcmd1 As ADODB.Command' *************************************************************
    ' Demonstrate the use of AddADOCommand by opening an ADO data command,
    ' adding the data source to the report, and then adding a field
    ' to the report that uses that data source.
    '
    Private Sub cmdADO_Click()
        Dim fld As FieldObject
        Dim strCnn As String
        
        ' Open the data connection
        Set cnn1 = New ADODB.Connection
        strCnn = "Provider=MSDASQL;Persist Security Info=False;Data Source=Xtreme Sample Database 9;Mode=Read"
        cnn1.Open strCnn    ' Create a new instance of an ADO command object
        Set datcmd1 = New ADODB.Command
        Set datcmd1.ActiveConnection = cnn1
        datcmd1.CommandText = "Customer"
        datcmd1.CommandType = adCmdTable    ' Add the datasource to the report
        m_Report.Database.AddADOCommand cnn1, datcmd1
        ' Add a new field object to the report and set the field object to use
        ' the new data source.
        Set fld = m_Report.Section3.AddFieldObject("{ado.Customer Name}", 0, 0)
        LoadReport
    End Sub
    ---------------------------------------------------------------------------------------
    按下按钮后提示 “未启用创建功能”问题是不是出在第一句 “Dim m_Report As New CrystalReport1” ? 该怎么改??
      

  2.   

    Dim conn As New ADODB.Connection
      Dim rs As New ADODB.Recordset
      Dim CApp As New CRAXDRT.Application
      Dim CRpt As New CRAXDRT.Report
      Dim i As Integer
     
      conn.ConnectionString = ".1;PersiProvider=SQLOLEDBst Security Info=False;User ID=sa;Initial Catalog=aa;Data Source=das"
      conn.Open
      rs.Open "select * from ad ", conn, adOpenStatic, adLockOptimistic
     
      Set CRpt = CApp.OpenReport("E:\Temp\text.rpt")
      For i = 1 To CRpt.Database.Tables.Count
          If CRpt.Database.Tables.Item(i).Name = "ado" Then
               CRpt.Database.Tables(i).SetDataSource rs
           End If
            
      Next
     
       CR.ReportSource = CRpt
       CR.ViewReport
       CR.Zoom 200
       CR.Width = Me.ScaleWidth
       CR.Height = Me.ScaleHeight