How to filter a Crystal Report by dates ?

Posted on 2004-12-01
Last Modified: 2008-02-26
Hi guys, I need to make a filter with date fields, to let a user ask for a range of dates. I'm working with VB6, SQL7 and Crystal 8. I'm using the RecordSelectionFormula method like this: Report.RecordSelectionFormula = "{Table.Date} >= " & Chr(34) & msktxtDate.Text & Chr(34).

But that command gives an error like the field wouldn't be date-time. I tested different choices, by using CDate() function, or the SQL CAST command but still the same.

I hope you can help me !
Question by:LillianJohnsson
    LVL 5

    Accepted Solution


    You could try ...

    Report.RecordSelectionFormula = "{Table.Date} >= Date(" & msktxtDate.Text & ")"

    However if msktxtDate.Text is ambiguous (i.e. date could be British or American) then you might be better to split it like ...

    If msktxtDate.Text = "10/02/2004"

    Report.RecordSelectionFormula = "{Table.Date} >= Date(" & MID(msktxtDate.Text,7,4) & "," & MID(msktxtDate.Text,4,2) & "," & MID(msktxtDate.Text,1,2) & ")"

    Either way you are telling Crystal what you are giving it is a date.
    LVL 1

    Expert Comment

    You may need to put a hash on either side of you date

    Report.RecordSelectionFormula = "{Table.Date} >= " + "#" + msktxtDate.Text + "#"

    also be careful with your date format dd/mm/yyyy or mm/dd/yyyy, this can be an issue, it could be either

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now