Print Page | Close Window

Date range example

Printed From: Crystal Reports Book
Category: Crystal Reports .NET 2003
Forum Name: Writing Code
Forum Discription: .NET 2003 programming API, report integration
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=339
Printed Date: 02 May 2024 at 4:45am


Topic: Date range example
Posted By: aleplgr
Subject: Date range example
Date Posted: 16 Mar 2007 at 9:19am
Hi, I'm using 2 DateTimePickers and a Button to display a report in a date range,  in the report I have no formulas and I only show the Order Date and the Order Id of the xtreme database Orders table.
this is the routine in the Button:
 
Private Sub btnReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReport.Click

Dim myReport As New rptOrderHistory

Dim OrdersPreview As New frmPreviewReport(myReport)

If chkUseDates.Checked Then

Dim DateRange As String

DateRange = "{Orders.Order Date} in CDate(DateTimePicker1) to CDate(DateTimePicker2)"

myReport.DataDefinition.RecordSelectionFormula = DateRange

MsgBox(DateRange)

End If

 OrdersPreview.ShowDialog()

 End Sub

 

I'm getting a runtime error, the message is that there's a ) missing,

the DateRange string is exactlly this
"{Orders.Order Date} in CDate(DateTimePicker1) to CDate(DateTimePicker2)"
but it doesn't work because I need to pass the DateTimePicker1 and 2 as strings



Replies:
Posted By: BrianBischof
Date Posted: 16 Mar 2007 at 9:43am
Whenever you modify the selection formula from your .NET code, you have to say to yourself, "If I entered it in this way in Crystal, would it work?" And the answer for this formula is obviously No. That's because Crystal doesn't know what DateTime Picker is. However, in your other post you know that Crystal likes it when you say CDate("03/01/2005"). So your .NET program should say that as well. Exactly that.
DateRange = "{Orders.Order Date} in CDate(""" + DateTimePicker1.Text + """) to CDate(""" + DateTimePicker2.Text + """)"

Now, make sure I didn't screw up the quotes. I used three so that I can terminate the string and also hard-code a quote around the date as well. You might have to play with it to make it work, but that is the idea.


-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>


Posted By: aleplgr
Date Posted: 16 Mar 2007 at 9:56am
Thanks!!!!!! Smile Smile it works exactlly as you wrote it!!


Posted By: BrianBischof
Date Posted: 16 Mar 2007 at 10:13am


-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>



Print Page | Close Window