[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1064
  • Last Modified:

Passing Crystal Reports SelectionFormula along to a subreport

Hey, I'm struggling through incorporating a crystal report into my ASP.NET web page.  My method is to create a DAO connection to my MDB file in my .rpt, and then on my report form with the CR viewer, I set up a selection formula as in the code below.  As you can see I narrow the report down to a detailed report of a single record.

So now I have to add a second table based on a related database table (the "milestones" associated with my plan record), and apparently I have to do this using a subreport.  I have created a separate, working RPT object that lists ALL of the milestones for all plans, and I added a subreport to my Plan report and connected it to this RPT.  This works fine so far, I open up  my plans report and I see the subreport listing all milestones for all plans, however I'd like to filter this down using the same SelectionFormula so that it only shows records in the subreport that pertain to the main report.  How do I set a SelectionFormula for the subreport from my main webform / report viewer?

A code snippet (hopefully it's that simple) would be *much* appreciated.  Thanks very much...
Partial Class FormReportPlan
    Inherits System.Web.UI.Page
 
    Private customerReport As ReportDocument
 
    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
 
        ConfigureCrystalReports()
 
    End Sub
 
    Private Sub ConfigureCrystalReports()
 
        Dim rec As String = Request.QueryString("rec")
 
        customerReport = New ReportDocument()
        customerReport.Load(Server.MapPath("ReportPlan.rpt"))
 
        If Not rec Is Nothing Then
            CrystalReportViewer1.SelectionFormula = "{Plans_View.Plan Number} = '" + rec + "'"
        End If
 
        CrystalReportViewer1.ReportSource = customerReport
 
    End Sub
 
End Class

Open in new window

0
riceman0
Asked:
riceman0
  • 2
1 Solution
 
raterusCommented:
The answer to your question here is to use Subreport Links (Right click on the subreport in your main report and you'll see the option "Change Subreport links").

You can read up on them as I'm not the smartest with them, but basically you can link data between the reports, so your subreport uses data in the main report to select it's data.
0
 
mlmccCommented:
WHy do you need to add this as a subreport?

If it is a related table you should be able to simply add the table to the main report and link it appropriately.

To use the subreport links
Right click the subreport
Click CHANGE SUBREPORT LINKS
Select the ID field from the main report
Select the related foield from the subreport field list
CLick the box the select records based on the field

mlmcc
0
 
riceman0Author Commented:

"WHy do you need to add this as a subreport?"

Please see my accepted answer to this question.  I would love to do this more simply.

http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_23469076.html

"If it is a related table you should be able to simply add the table to the main report and link it appropriately."

Do you still think I can do this?  I want several different tables/lists.
0
 
mlmccCommented:
You are correct, in that scenario you need to use subreports.

mlmcc
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now