Ok wasn't quite sure as to whether I should post this in here or in the reporting forum but as it seems to be an error in my VB code, I posted it here. I am trying to load a report into a CRViewer control and for some reason the Selection Formula is not being applied at all. Here is my report generation code
I was wondering if anyone else has run into this issue and might know what is going on.Code:Friend Function ViewReport(ByVal sReportName As String, ByVal sSelectionFormula As String, ByVal ParamArray param As String()) As Boolean Dim intCounter As Integer Dim intCounter1 As Integer objReport = New CrystalDecisions.CrystalReports.Engine.ReportDocument Dim ConInfo As New CrystalDecisions.Shared.TableLogOnInfo Dim paraValue As New CrystalDecisions.Shared.ParameterDiscreteValue Dim currValue As CrystalDecisions.Shared.ParameterValues Dim mySubReportObject As CrystalDecisions.CrystalReports.Engine.SubreportObject mySubRepDoc = New CrystalDecisions.CrystalReports.Engine.ReportDocument Dim strVal() As String Dim index As Integer Try Dim ar As New RadSafety.Adms.Reports.Report() ar.ReportName = strReport objReport = ar.GetReport() intCounter = objReport.DataDefinition.ParameterFields.Count If intCounter = 1 Then If InStr(objReport.DataDefinition.ParameterFields(0).ParameterFieldName, ".", CompareMethod.Text) > 0 Then intCounter = 0 End If End If If intCounter > 0 And param.Length > 0 Then For index = 0 To param.GetUpperBound(0) If InStr(param(index), "=") > 0 Then strVal = param(index).Split("=") paraValue.Value = strVal(1) currValue = objReport.DataDefinition.ParameterFields(strVal(0)).CurrentValues currValue.Add(paraValue) objReport.DataDefinition.ParameterFields(strVal(0)).ApplyCurrentValues(currValue) End If Next End If ConInfo.ConnectionInfo.ServerName = ServerName ConInfo.ConnectionInfo.UserID = "USERNAME" ConInfo.ConnectionInfo.Password = "PASSWORD" ConInfo.ConnectionInfo.DatabaseName = "ADMS2_" & SiteName For intCounter = 0 To objReport.Database.Tables.Count - 1 objReport.Database.Tables(intCounter).ApplyLogOnInfo(ConInfo) Next For index = 0 To objReport.ReportDefinition.Sections.Count - 1 For intCounter = 0 To objReport.ReportDefinition.Sections(index).ReportObjects.Count - 1 With objReport.ReportDefinition.Sections(index) If .ReportObjects(intCounter).Kind = CrystalDecisions.Shared.ReportObjectKind.SubreportObject Then mySubReportObject = CType(.ReportObjects(intCounter), CrystalDecisions.CrystalReports.Engine.SubreportObject) mySubRepDoc = mySubReportObject.OpenSubreport(mySubReportObject.SubreportName) For intCounter1 = 0 To mySubRepDoc.Database.Tables.Count - 1 mySubRepDoc.Database.Tables(intCounter1).ApplyLogOnInfo(ConInfo) Next End If End With Next Next If sSelectionFormula.Length > 0 Then 'This is the line that is not being applied to the report. objReport.RecordSelectionFormula = sSelectionFormula End If crViewer.ReportSource = Nothing crViewer.ReportSource = objReport crViewer.Zoom(1) crViewer.Show() Application.DoEvents() Me.Text = sReportName MyBase.Visible = True Me.BringToFront() Return True Catch ex As System.Exception MsgBox(ex.Message) End Try End Function
I am using VB2005 and CRXI Release 2




Reply With Quote