Results 1 to 6 of 6

Thread: Someone please give me an example of code for a crystal report with a subreport

  1. #1

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Someone please give me an example of code for a crystal report with a subreport

    I really need the above example using the designer in VB plz.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Someone please give me an example of code for a crystal report with a subreport

    I think you will need to clarify your question. Code? Of all the subreports I have created not once did I need to code anything.

  3. #3
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Someone please give me an example of code for a crystal report with a subreport

    I have Crystal reports with sub reports, but I don't use the designer in VB. I create them as stand alone reports and call them from the code.
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Someone please give me an example of code for a crystal report with a subreport

    Moved to reporting

  5. #5

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: Someone please give me an example of code for a crystal report with a subreport

    Hi Guys,

    I have the foolowing code in my vb app to generate my report:

    Code:
    Sub PopulateReport(Cid As Integer)
    Dim con As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim rs2 As ADODB.Recordset
    Dim sql As String
    Dim sql2 As String
    
    Set con = GetConnection
    
    lvwCompany.Enabled = False
    
    Set oReport = New CrystalReport1   'oApp.OpenReport(App.Path & "\Reports\MyReport.rpt", 1)
    
    
    sql = "select ci.ipkcompanyid,ci.companyname,ci.companyaddress,ci.cgroup,ci.area,ci.propertyowner," & _
          "ci.callfrequency,ci.leaseexpires,ci.business,ci.followupdate,ci.comments,ca.calldate,ca.details,ca.ipkcallid,u.username as 'callby'" & _
          " FROM " & _
          "tblcalls ca,tblcompanyinfo ci,tblusers u " & _
          "WHERE ca.ifkcompanyid = ci.ipkcompanyid " & _
          "AND ca.callby = u.ipkuserid " & _
          "AND ca.ifkcompanyid = " & Cid & " ORDER BY ca.calldate DESC;"
          
          Set rs = con.Execute(sql)
    
    sql2 = "SELECT ci.ipkcompanyid,co.ifkcompanyid,co.contname FROM " & _
           "tblcontacts co,tblcompanyinfo ci WHERE co.ifkcompanyid = ci.ipkcompanyid " & _
           "AND co.ifkcompanyid = " & Cid & ";"
           
           Set rs2 = con.Execute(sql2)
           
    
     
           With oReport
            .Database.SetDataSource rs, , 1
            .OpenSubreport("Contacts").Database.SetDataSource rs2, , 1
            .PaperOrientation = 1
            .PaperSize = 2
            .EnableParameterPrompting = False
            .DiscardSavedData
           End With
           
            Delay 2 'give report time to load
            CrystalActiveXReportViewer1.ReportSource = oReport
            CrystalActiveXReportViewer1.ViewReport
    
    lvwCompany.Enabled = True
          
    End Sub
    In my designer for the report I have created a command for the main report and a command for the sub report:

    Main Report Command:

    Code:
    select ci.ipkcompanyid,ci.companyname,ci.companyaddress,ci.cgroup,ci.area,ci.propertyowner,ci.callfrequency,ci.leaseexpires,ci.business,ci.followupdate,ci.comments,ca.calldate,ca.ipkcallid,u.username as 'callby',ca.details from tblcalls ca,tblcompanyinfo ci,tblusers u
    where ca.ifkcompanyid = ci.ipkcompanyid
    AND ca.callby = u.ipkuserid ORDER BY ca.calldate DESC
    Sub Report Command:

    Code:
    SELECT ci.ipkcompanyid,co.ifkcompanyid,co.contname FROM tblcontacts co,tblcompanyinfo ci WHERE co.ifkcompanyid = ci.ipkcompanyid
    Is this the wrong way of doing it. Please advise me. I am really stuck and I am new to CR XI.

    One last thing guys, My main report works great but my SubReport displays nothing at all. I would really appreciate a fix to this problem.
    Last edited by Nitesh; Oct 3rd, 2007 at 12:58 AM. Reason: Addition of Informayion

  6. #6

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: Someone please give me an example of code for a crystal report with a subreport

    someone please chack my subreport query. That is the problem. Because I hav created another subreport in which I just added the tables from which to use in the database expert, and I did not add a command and the subreport works fine. But I need to extract this info using a command.

Posting Permissions

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



Click Here to Expand Forum to Full Width