Results 1 to 2 of 2

Thread: [RESOLVED] [2005] Setting Crystal Report SelectionFormula in VB

  1. #1

    Thread Starter
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Resolved [RESOLVED] [2005] Setting Crystal Report SelectionFormula in VB

    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
    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 was wondering if anyone else has run into this issue and might know what is going on.

    I am using VB2005 and CRXI Release 2
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  2. #2

    Thread Starter
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: [2005] Setting Crystal Report SelectionFormula in VB

    Ok well I found out what the issue is. It seems that there is code in the form that contains the Report Viewer that sets the Selection Formula to nothing.

    If anyone else has these issues this is how I fixed it.

    In the Form designer's Initialze Component method I removed the following lines and it now applys selection formulas properly.

    Code:
    crViewer.SelectionFormula = ""
    'and
    crViewer.ViewTimeSelectionFormula = ""
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

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