foody
November 13th, 2007, 09:05 AM
Hello,
I am developing using VB.NET and I have a major problem with my crystal report. When I want to attempt to display information on the crystal report with a condition that UserID = <Value> and ReportID = <Value> using RecordSelectionFormula for both the main report and it's subreport I get the following problem:
Main report displays ALL values and sub report displays the correct value, or sometimes it is the other way around depending on how I adjust the code but it is neither both. How can I fix this problem?
Below is the code:
1 Public Sub BindReportDetailsData(ByVal UserID As String, ByVal ReportID As Long, ByVal _Path As String, ByVal _ReportViewer As CrystalDecisions.Web.CrystalReportViewer)
2 Dim _Report As New ReportDocument
3 Dim _MySubReport As New ReportDocument
4 Dim _MyReport As ReportObject = Nothing
5 Dim _SubReportObject As SubreportObject = Nothing
6
7
8
9 _Report.Load(_Path)
10 _Report.SetDatabaseLogon("foody", "amiga1200")
11
12 For Each _MyReport In _Report.ReportDefinition.ReportObjects
13 If _MyReport.Kind = CrystalDecisions.Shared.ReportObjectKind.SubreportObject Then
14 _Report.DataDefinition.RecordSelectionFormula = "{ExpenseUsers.UserID}= ""{" & UserID & "} AND {ExpenseItems.ReportID} = " & ReportID & ""
15 _SubReportObject = CType(_MyReport, CrystalDecisions.CrystalReports.Engine.SubreportObject)
16 _MySubReport = _SubReportObject.OpenSubreport(_SubReportObject.SubreportName)
17 _MySubReport.DataDefinition.RecordSelectionFormula = "{ExpenseUsers.UserID}= ""{" & UserID & "} AND {ExpenseItems.ReportID} = " & ReportID & ""
18 _ReportViewer.DisplayToolbar = True
19 _ReportViewer.HasRefreshButton = False
20 _ReportViewer.HasSearchButton = False
21 _ReportViewer.HasToggleGroupTreeButton = False
22 _ReportViewer.HasViewList = False
23 _ReportViewer.HasZoomFactorList = False
24 _ReportViewer.HasPageNavigationButtons = False
25 _ReportViewer.HasGotoPageButton = False
26 _ReportViewer.HasDrillUpButton = False
27 _ReportViewer.HasCrystalLogo = False
28 _ReportViewer.HasPrintButton = True
29 _ReportViewer.ReportSource = _Report
30 End If
31 Next
32
33 '_Report.Subreports.Item(0).DataDefinition.RecordSelectionFormula = "{ExpenseItems.ReportID}=" & _ReportID & ""
34
35
36 _ReportViewer.DataBind()
37 End Sub
Can someone help me please? Thanks in advance.
I am developing using VB.NET and I have a major problem with my crystal report. When I want to attempt to display information on the crystal report with a condition that UserID = <Value> and ReportID = <Value> using RecordSelectionFormula for both the main report and it's subreport I get the following problem:
Main report displays ALL values and sub report displays the correct value, or sometimes it is the other way around depending on how I adjust the code but it is neither both. How can I fix this problem?
Below is the code:
1 Public Sub BindReportDetailsData(ByVal UserID As String, ByVal ReportID As Long, ByVal _Path As String, ByVal _ReportViewer As CrystalDecisions.Web.CrystalReportViewer)
2 Dim _Report As New ReportDocument
3 Dim _MySubReport As New ReportDocument
4 Dim _MyReport As ReportObject = Nothing
5 Dim _SubReportObject As SubreportObject = Nothing
6
7
8
9 _Report.Load(_Path)
10 _Report.SetDatabaseLogon("foody", "amiga1200")
11
12 For Each _MyReport In _Report.ReportDefinition.ReportObjects
13 If _MyReport.Kind = CrystalDecisions.Shared.ReportObjectKind.SubreportObject Then
14 _Report.DataDefinition.RecordSelectionFormula = "{ExpenseUsers.UserID}= ""{" & UserID & "} AND {ExpenseItems.ReportID} = " & ReportID & ""
15 _SubReportObject = CType(_MyReport, CrystalDecisions.CrystalReports.Engine.SubreportObject)
16 _MySubReport = _SubReportObject.OpenSubreport(_SubReportObject.SubreportName)
17 _MySubReport.DataDefinition.RecordSelectionFormula = "{ExpenseUsers.UserID}= ""{" & UserID & "} AND {ExpenseItems.ReportID} = " & ReportID & ""
18 _ReportViewer.DisplayToolbar = True
19 _ReportViewer.HasRefreshButton = False
20 _ReportViewer.HasSearchButton = False
21 _ReportViewer.HasToggleGroupTreeButton = False
22 _ReportViewer.HasViewList = False
23 _ReportViewer.HasZoomFactorList = False
24 _ReportViewer.HasPageNavigationButtons = False
25 _ReportViewer.HasGotoPageButton = False
26 _ReportViewer.HasDrillUpButton = False
27 _ReportViewer.HasCrystalLogo = False
28 _ReportViewer.HasPrintButton = True
29 _ReportViewer.ReportSource = _Report
30 End If
31 Next
32
33 '_Report.Subreports.Item(0).DataDefinition.RecordSelectionFormula = "{ExpenseItems.ReportID}=" & _ReportID & ""
34
35
36 _ReportViewer.DataBind()
37 End Sub
Can someone help me please? Thanks in advance.