Date range in Crystal Report

korsario

New member
Joined
Aug 10, 2004
Messages
2


Hi. Someone could help me. Im trying to program a crystal report, but it shouold receive a data range (ex. 2004-03-01 and 2004-03-31). My problem is the reports shows all the rows in the table. In other words, how can I include the clause "Where idService=213" or "where date between=..."

Thank you very much.

 
korsario said:


Hi. Someone could help me. Im trying to program a crystal report, but it shouold receive a data range (ex. 2004-03-01 and 2004-03-31). My problem is the reports shows all the rows in the table. In other words, how can I include the clause "Where idService=213" or "where date between=..."

Thank you very much.


I create 2 parameters in my Crystal Report and create a Record Formula using the parameters.

Record Forumla:
{tblHistory.DateEntered} >= {?pFromDate} and {tblHistory.DateEntered} <= {?pToDate}

I then pass the date range from vb to crystal using the following code:

Dim pfs As New CrystalDecisions.Shared.ParameterFields
Dim pf As CrystalDecisions.Shared.ParameterField
Dim pfDiscrete As CrystalDecisions.Shared.ParameterDiscreteValue

Add and set the FromDate
pf = New CrystalDecisions.Shared.ParameterField
pf.ParameterFieldName = "pFromDate"
pfDiscrete = New CrystalDecisions.Shared.ParameterDiscreteValue
pfDiscrete.Value = DateValue(txtFromDate.Text)
pf.CurrentValues.Add(pfDiscrete)
pfs.Add(pf)

Add and set the ToDate
pf = New CrystalDecisions.Shared.ParameterField
pf.ParameterFieldName = "pToDate"
pfDiscrete = New CrystalDecisions.Shared.ParameterDiscreteValue
pfDiscrete.Value = DateValue(txtToDate.Text)
pf.CurrentValues.Add(pfDiscrete)
pfs.Add(pf)

Assign the parameter collection to the viewer
CrystalReportViewer.ParameterFieldInfo = pfs
CrystalReportViewer.ReportSource = rptHistory
CrystalReportViewer.Zoom(1)

You can also use the parameters in the report heading if necessary.

Hope this helps.
 
A better way

Thank you very much!!!!

It gave me a better idea.

I could just use:

reporter.RecordSelectionFormula = "{Command.idUnidad}=" & comboUnidades.Text

And thats all!!!!

But you gave me the idea!, thank you very much dude!!
 
Crystal Report: Date Range

Hi! I used your code.. but I cant seem to make it work.. the values dont filter... where did you put this code? in page load() or somewhere else? and can you post the whole function or sub program? im just a beginner in crystal reports and i really dont know how to make it work. Id really really be grateful if you would help me.. :D Thanks in advance...




ryan1107 said:
I create 2 parameters in my Crystal Report and create a Record Formula using the parameters.

Record Forumla:
{tblHistory.DateEntered} >= {?pFromDate} and {tblHistory.DateEntered} <= {?pToDate}

I then pass the date range from vb to crystal using the following code:

Dim pfs As New CrystalDecisions.Shared.ParameterFields
Dim pf As CrystalDecisions.Shared.ParameterField
Dim pfDiscrete As CrystalDecisions.Shared.ParameterDiscreteValue

Add and set the FromDate
pf = New CrystalDecisions.Shared.ParameterField
pf.ParameterFieldName = "pFromDate"
pfDiscrete = New CrystalDecisions.Shared.ParameterDiscreteValue
pfDiscrete.Value = DateValue(txtFromDate.Text)
pf.CurrentValues.Add(pfDiscrete)
pfs.Add(pf)

Add and set the ToDate
pf = New CrystalDecisions.Shared.ParameterField
pf.ParameterFieldName = "pToDate"
pfDiscrete = New CrystalDecisions.Shared.ParameterDiscreteValue
pfDiscrete.Value = DateValue(txtToDate.Text)
pf.CurrentValues.Add(pfDiscrete)
pfs.Add(pf)

Assign the parameter collection to the viewer
CrystalReportViewer.ParameterFieldInfo = pfs
CrystalReportViewer.ReportSource = rptHistory
CrystalReportViewer.Zoom(1)

You can also use the parameters in the report heading if necessary.

Hope this helps.
 
Back
Top