How to call crystal reports 8.5 from vb 6.0-VBForums
Results 1 to 6 of 6

Thread: How to call crystal reports 8.5 from vb 6.0

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    2

    How to call crystal reports 8.5 from vb 6.0

    Hi there,
    Can anyone help me out,

    I am using crystal reports 8.5 and visual basic 6.0

    I created a report and want to call it using vb6.0 and then show it

    ?How can i do this??
    PS: I tried using crviewer but could not get anything (when i run, either the form is blank and gets hanged up)
    Thanks very much in advance

    I am attaching the code I used :
    VB Code:
    1. Dim CRXApplication As CRAXDDRT20.Application
    2. Dim CRXReport As CRAXDDRT20.report
    3. Dim CRXDatabase As CRAXDDRT20.Database
    4. Dim db As New ADODB.Connection
    5. Dim rs As New ADODB.Recordset
    6.  
    7. Private Sub Form_Load()
    8.     Me.WindowState = 2 'Maximized
    9.  
    10. Set db = New ADODB.Connection
    11.   cnn = "driver=sql server;server=my_server;database=mytest;uid=my_uid;pwd=my_pwd"
    12.    db.Open cnn
    13.     Set rs = New ADODB.Recordset
    14.      rs.Open "select distinct deptic,name,attdic from view_icnotequal where year(attd_date)='2005' and month(attd_date)='09' and dept_id=13", db, adOpenStatic, adLockReadOnly
    15.      
    16.     Set CRXApplication = New CRAXDDRT20.Application
    17.     Set CRXReport = New CRAXDDRT20.report
    18.     Set CRXDatabase = CRXReport.Database
    19.     Set CRXReport = CRXApplication.OpenReport("d:\sarada\testreport1.rpt", 1)
    20.     CRXReport.DiscardSavedData
    21.     CRXReport.Database.Tables(1).SetDataSource rs, 3
    22.      
    23.     CRViewer.ReportSource = CRXReport
    24.     CRViewer.ViewReport
    25.    
    26. '*// Clean up
    27.     Set CRXDatabase = Nothing
    28.     Set CRXReport = Nothing
    29.     Set CRXApplication = Nothing
    30.  
    31. End Sub
    32.  
    33. Private Sub Form_Resize()
    34.     CRViewer.Top = 0
    35.     CRViewer.Left = 0
    36.     CRViewer.Height = ScaleHeight
    37.     CRViewer.Width = ScaleWidth
    38. End Sub
    39.  
    40.  
    41. Private Sub Form_Terminate()
    42.      
    43.     '*// Clean up
    44.     Set CRXDatabase = Nothing
    45.     Set CRXReport = Nothing
    46.     Set CRXApplication = Nothing
    47. End Sub
    thanks very much

    Regards







    Edit: Added [vbcode][/vbcode] tags for clarity. - Hack
    Last edited by Hack; Nov 2nd, 2005 at 05:30 AM.

  2. #2
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,915

    Re: How to call crystal reports 8.5 from vb 6.0

    You don't appear to be using this reference, Dim CRXDatabase As CRAXDDRT20.Database so you may as well get rid of it. Have you tried this
    VB Code:
    1. CRXReport.Database.Tables([color=red][b]0[/b][/color]).SetDataSource rs, 3
    In VB.Net this starts at zero, don't know whether it's the same for VB6, but it's worth a shot.
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    2

    Re: How to call crystal reports 8.5 from vb 6.0

    Hi
    Thanks for your help..
    but unfortunately, it did not work, when ever i try to add 0 to
    CRXReport.Database.Tables(1).SetDataSource rs, 3
    then it is saying subscript out of range.

    Any more ideas??

    Thanks any way..

  4. #4
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,915

    Re: How to call crystal reports 8.5 from vb 6.0

    This code works for me. This is Crystal 9 but it it should work similarly for 8.5, you'll just need to change the references form CRAXDRT to CRAXDRT20.
    VB Code:
    1. Option Explicit
    2.  
    3. Private crApp As CRAXDRT.Application
    4. Private crReport As CRAXDRT.Report
    5.  
    6. Private Const Provider As String = "Microsoft.Jet.OLEDB.4.0"
    7. Private cn As ADODB.Connection
    8. Private rs As ADODB.Recordset
    9.  
    10. Private Sub cmdPrint_Click()
    11.  
    12.     Dim sql As String
    13.     Set rs = New ADODB.Recordset
    14.    
    15.     sql = "SELECT [Field1], [Field2], [Field3] "
    16.     sql = sql & "From [MyTable] "
    17.     sql = sql & "WHERE [MyField] = '" & SomeValue & "'"
    18.    
    19.     rs.Open sql, cn, adOpenKeyset, adLockOptimistic
    20.    
    21.     Set crApp = New CRAXDRT.Application
    22.     Set crReport = crApp.OpenReport("MyReport.rpt")
    23.     crReport.Database.Tables(1).SetDataSource rs
    24.  
    25.     CRViewer.ReportSource = crReport
    26.     CRViewer.ViewReport
    27.    
    28.     rs.Close
    29.     Set rs = Nothing
    30.    
    31.     Set crReport = Nothing
    32.     Set crApp = Nothing
    33.    
    34. End Sub
    35.  
    36. Private Sub Form_Load()
    37.  
    38.     Set cn = New ADODB.Connection
    39.     cn.Open "Provider=" & Provider & ";Data Source=MyDb.mdb"
    40.    
    41. End Sub
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  5. #5
    New Member
    Join Date
    Jul 2008
    Posts
    2

    Re: How to call crystal reports 8.5 from vb 6.0

    I have seen your sample but when type the code below it can not work. what anything should I add in referent because declare it can not show the class CRAXDDRT20.report. what can I do??? Thank In Advance.

  6. #6
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,856

    Re: How to call crystal reports 8.5 from vb 6.0

    Try :
    Code:
    CRXReport.DiscardSavedData
    CRXReport.Database.SetDataSource rs

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.