Filter Crystal Report with date range on VB.net

My Report.rpt has two parameters "datestart" and "dateend", and
the form has two DTPickers to filter result.
Following codes work well on VB6, now I am learning VB.NET, could someone help me to achieve such function on VB.NET? many thanks.

Dim Appl As New CRAXDRT.Application
Dim Report As New CRAXDRT.Report
DTPicker1.Value = Format(Now, "DD/MM/YY")
DTPicker2.Value = Format(Now, "DD/MM/YY")
Set Report = Appl.OpenReport(App.Path & "\" & "Report.rpt")
CRViewer91.ReportSource = Report
Report.EnableParameterPrompting = False
Report.ParameterFields.GetItemByName("datestart").AddCurrentValue DTPicker1.Value
Report.ParameterFields.GetItemByName("dateend").AddCurrentValue DTPicker2.Value
CRViewer91.ViewReport
gavvicAsked:
Who is Participating?
 
planoczConnect With a Mentor Commented:
the Imports --- you have to add in the references
All the small s words like -- sDBName -- there string var's that you have to add.

That should do it.

Here is where I found good examples for getting started in VB.Net

.....http://msdn.microsoft.com/vbasic/downloads/samples/101samples.aspx

Link for ASP programs...

http://msdn.microsoft.com/asp.net/downloads/kits/default.aspx 


0
 
planoczCommented:
Sample code....

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.ReportSource
Imports CrystalDecisions.Shared

  Public myReport As New ReportDocument        'Gobal Report Doc

  Private Sub Parmas(ByVal myReport) 'FOR Dates and Ranges
        ' Objects used to set the parameters in the report
        Dim pvCollection As New ParameterValues
        Dim pdvID As New ParameterDiscreteValue
        Dim pdvStartName As New ParameterDiscreteValue
        Dim pdvEndName As New ParameterDiscreteValue
        Try
                '********************************* ID **********************************
                ' Set the discreet value to the Start Date.
                pdvID.Value = sID
                ' Add it to the parameter collection.
                pvCollection.Add(pdvID)
                ' Apply the current parameter values.
                myReport.DataDefinition.ParameterFields("Id").ApplyCurrentValues(pvCollection)

                '********************************* Start Date **********************************
                pdvStartName.Value = sStartDate
                pvCollection.Add(pdvStartName)
                myReport.DataDefinition.ParameterFields("Start Date").ApplyCurrentValues(pvCollection)

                '********************************* End Date **********************************
                pdvEndName.Value = sEndDate
                pvCollection.Add(pdvEndName)
                myReport.DataDefinition.ParameterFields("End Date").ApplyCurrentValues(pvCollection)
   
        Catch Exp As ParameterFieldException
            MsgBox("Incorrect Parameter Field." & vbNewLine & "In Parmas Procedure Code", _
                    MsgBoxStyle.Critical, "Load Report Error")
        Catch Exp As InvalidArgumentException
            MsgBox(Exp.Message & vbNewLine & "In Parmas Procedure Code", MsgBoxStyle.Critical, "General Error")
        Catch Exp As Exception
            MsgBox(Exp.Message & vbNewLine & "In Parmas Procedure Code", MsgBoxStyle.Critical, "General Error")
        End Try
    End Sub

 Private Sub ViewCR_PDF()
        sReportName = "MYReport.rpt"
        GetReportConnection(myReport)
        Parmas(myReport)
        Try
            crDateView.DisplayGroupTree = False
            ' Set the report source for the crystal reports viewer to the report instance.
            'crDateView is the CR Viewer
             crDateView.ReportSource = myReport
            'Good for total pages of all of the query reported
            'Dim str As String
            'str = myReport.FormatEngine.GetLastPageNumber(New ReportPageRequestContext)

            ' Zoom viewer to fit to the whole page so the user can see the report
            crDateView.Zoom(1) '1 is page width and 2 is view whole page)
            'Go get the Last Page Count Number
            crDateView.ShowLastPage()
            iPageCount = crDateView.GetCurrentPageNumber.ToString
        Catch Exp As LoadSaveReportException
            MsgBox("Incorrect path for loading report.", _
                    MsgBoxStyle.Critical, "Load Report Error")
        Catch Exp As Exception
            MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error")
        End Try
    End Sub

   Private Sub GetReportConnection(ByVal myReport)
        ' Objects used to set the proper database connection information
        Dim tbCurrent As CrystalDecisions.CrystalReports.Engine.Table
        Dim tliCurrent As CrystalDecisions.Shared.TableLogOnInfo

        Try
            ' Load the report
            myReport.Load(sMYPath & sReportName, CrystalDecisions.[Shared].OpenReportMethod.OpenReportByTempCopy)
            ' Set the connection information for all the tables used in the report
            For Each tbCurrent In myReport.Database.Tables
                tliCurrent = tbCurrent.LogOnInfo
                With tliCurrent.ConnectionInfo
                    .ServerName = sDBServer
                    .UserID = sUSERid
                    .Password = ""
                    .DatabaseName = sDBName
                End With
                tbCurrent.ApplyLogOnInfo(tliCurrent)
            Next tbCurrent
        Catch Exp As LoadSaveReportException
            MsgBox("Incorrect path for loading report.", _
                    MsgBoxStyle.Critical, "Load Report Error")
        Catch Exp As Exception
            MsgBox(Exp.Message & "   in GetReportConnection Procedure", MsgBoxStyle.Critical, "General Error")
        End Try
    End Sub

0
 
gavvicAuthor Commented:
Thank you for your reply, planocz. But I can not get it work with your sample code.  Lots of not declared items appear when I have tried it.

Is it possible that we could use "RecordSelectionFormula = " something like that to make the filter easier? or could you please give me more sources to understand more. Yep, I am just a starting out VB.net.
0
 
gavvicAuthor Commented:
After I have fixed my code, I get the result. Thanks for your help planocz.
0
All Courses

From novice to tech pro — start learning today.