Results 1 to 3 of 3

Thread: range in selection formula using crystal report

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Location
    selangor, Malaysia
    Posts
    71

    range in selection formula using crystal report

    Whut I try to do here I trying to get information based on range of date in order to display on CR 10. The thing is how am i going to declare in selection formula?Below is my code..plz anyone help me...



    Code:
    
    Dim crApp As CRAXDRT.Application
            Dim Report As CRAXDRT.Report
            Dim strSelectionfrm As String
            Set crApp = New CRAXDRT.Application
            Set Report = crApp.OpenReport("C:\Program Files\Microsoft Visual Studio\VB98\Projects\LeaveApp\LeaveForm4.rpt")
    
    
    
    Report.Database.Tables(1).SetLogOnInfo "SQL", "tebrauteguh", "sa", "sa"
            
            strSelectionfrm = "{tblLeaveApp.EmpNo}='" & ndEmpNoView & "'and {tblLeaveApp.Ldate}- {tblLeaveApp.Fdate}='" & ndDays & "'" '-->I try to select from range
           
            Report.RecordSelectionFormula = strSelectionfrm
            Report.DiscardSavedData
            Form9.CRV.ReportSource = Report
            Form9.CRV.ViewReport
            
            Form9.Show
            Me.Hide
            Me.MousePointer = vbNormal

  2. #2
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: range in selection formula using crystal report

    Not sure but you can try

    strSelectionfrm = "{tblLeaveApp.EmpNo}='" & ndEmpNoView & "'and DateDiff({tblLeaveApp.Ldate}, {tblLeaveApp.Fdate})='" & ndDays & "'" '-->I try to select from range

  3. #3
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972

    Re: range in selection formula using crystal report

    Here you have a few examples of ranges, i would advise you to use parameter fields, they aren't easer to use.
    Although when i print reports, i filter the sql data before printing the report so it will take few time to print, specially when you have big amounts of data:

    Commented are the lines that allow to load the report with specific sql query and uncommented is how to use parameter fields.

    This was taken from a current development. You might want to take a look to the idea and not specifically to the code

    Code:
        Public Sub printReportAssistencia(Optional ByVal NomeCliente As String = "", Optional ByVal NumHorasContrato As String = "", Optional ByVal NumAssistencia As Double = 0)
            Dim objRpt As CrystalDecisions.CrystalReports.Engine.ReportDocument = New CrystalDecisions.CrystalReports.Engine.ReportDocument()
            'Dim cnn As SqlConnection
            'Dim sql As String
            'Dim ds As New DataSet
            Dim __printPreview As New frmPrintPreview
    
            'cnn = New SqlConnection(GetConnectionString)
            'cnn.Open()
            'condicoesSQL = IIf(condicoesSQL = String.Empty, " WHERE 1=1", condicoesSQL)
            'condicoesSQL = " WHERE " & condicoesSQL
            'sql = "select * from Imoveis" & condicoesSQL
    
            'Dim dscmd As New SqlDataAdapter(sql, cnn)
            objRpt.Load(GetAppPath & "Reports\assistencia.rpt")
            objRpt.DataSourceConnections.Item(0).SetLogon(__sqlUser, __sqlPass)
            objRpt.DataSourceConnections.Item(0).SetConnection(__SQLserverName, __sqlDatabase, False)
            objRpt.SetDatabaseLogon(__sqlUser, __sqlPass, __SQLserverName, __sqlDatabase)
            'dscmd.Fill(ds)
            'objRpt.SetDataSource(ds.Tables(0))
            'objRpt.SetParameterValue("NumHorasContrato", """Número de horas do contrato aqui""")
            objRpt.DataDefinition.FormulaFields("NomeCliente").Text = NomeCliente
            objRpt.DataDefinition.FormulaFields("NumHorasContrato").Text = NumHorasContrato
            objRpt.DataDefinition.FormulaFields("NumAssistencia").Text = NumAssistencia
    
            __printPreview.MdiParent = MAIN_MDI_FORM
            __printPreview.CrystalReportViewer1.ReportSource = objRpt
            __printPreview.CrystalReportViewer1.Refresh()
            'CType(__printPreview.CrystalReportViewer1.Controls(4), ToolStrip).Items(CType(__printPreview.CrystalReportViewer1.Controls(4), ToolStrip).Items.Count - 1).BackgroundImage = My.Resources.ResLogos.logo
            __printPreview.Show()
        End Sub
    Last edited by TDQWERTY; Dec 2nd, 2011 at 10:19 AM.
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

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