Writing Code
 Crystal Reports Forum : Crystal Reports .NET 2003 : Writing Code
Message Icon Topic: Date range example Post Reply Post New Topic
Author Message
aleplgr
Newbie
Newbie


Joined: 09 Dec 2006
Online Status: Offline
Posts: 23
Quote aleplgr Replybullet Topic: Date range example
    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
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet 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>
IP IP Logged
aleplgr
Newbie
Newbie


Joined: 09 Dec 2006
Online Status: Offline
Posts: 23
Quote aleplgr Replybullet Posted: 16 Mar 2007 at 9:56am
Thanks!!!!!! Smile Smile it works exactlly as you wrote it!!
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet 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>
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.023 seconds.