Solved

Retrieve records by date parameter

Posted on 2001-07-27
7
292 Views
Last Modified: 2008-02-01
In VB 6 sp5 using MDB data file,  I wrote an application the uses Crystal reports pro 4.6 for its reporting engine. I need to open a report that uses a begining date criteria. I want all records to be displayed after the specified date variable. Actually once this works I want to specify a date span, but first things first.  I have tried many ways to make this happen but have been unsuccessful. The following code was tried..

The table "History" has a Date/TIme field in it named OrderDate. The format of the date stored is 7/27/01

The variable is a Date type that gets passed into it the date value from the  DTPicker control.


Reports.SelectionFormula = ""
strSelectCriteria = "{History.OrderDate} = " & BegDate
Reports.SelectionFormula = strSelectCriteria
Reports.ReportFileName = App.Path & "\custorderhistory.rpt"
Reports.DataFiles(0) = strPath
Reports.DiscardSavedData = True
Reports.Action = 1

I get a runtime error 20515
(Error in formula... A date is required here)

I also tried a few other things but this is the closest I got I think.

What would be the correct syntax used to do what I need? Can you also specify the correct syntax if I want to have my report generated by passing >= BegDate and <= EndDate?

Thanks in advance

0
Comment
Question by:techconcepts
7 Comments
 
LVL 12

Expert Comment

by:DRRYAN3
Comment Utility
The code you show above seems to be OK, except for the BegDate part.  You have to format the date properly to pass it to CRW.  I don't know exactly what that would be in version 4.6, but here's some links that may help

http://support.crystaldecisions.com/communityCS/TechnicalPapers/dateparm.exe.asp?AJID=4523819A15BB1046950A1ABA9CA60458

http://support.crystaldecisions.com/kbase/c2006910.asp?AJID=F51C603A73DF2E458956407F4B99E035

DRRYAN3
0
 

Accepted Solution

by:
dick3425 earned 50 total points
Comment Utility
If you are using a date parameter and you are using a version below 7 you need to write your select statement as follows:

{date field} = Date(?parameter field)

your date parameter field sould be entered yyyy,mm,dd.

0
 
LVL 12

Expert Comment

by:DRRYAN3
Comment Utility
dick3425,

I notice that you have recently joined.  Welcome to EE.  

In the Crystal Reports topic area, like many other areas on EE, the accepted convention is to leave your suggestions for the questioner as a comment instead of proposing them as an answer.  When you post a proposed answer, the question is moved out of the open questions area and into the locked questions area.  Most longer term users here (the "experts") generally don't look there for questions to answer.  This can deprive the questioner of other suggestions from other experts.

If you feel you have THE 110% right answer, then propose an answer.

Just wanted to save you some grief down the road.

DRRYAN3
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:techconcepts
Comment Utility
DRRYAN3,

It seems that version 4.6 doesnt accept parameter statement. Maybe you could show me more of an example on how this could lay into the code staement if this works for 4.6. If this works, then you would get the points. I will reject your answer without disrespect in search for either a bit more info on your proposed answer or the final solution to my problem.  In dick3425's comment, the links refered to version 5.0 and above that used the parameter statement. Maybe the solution here would be to upgrade to the later ocx report engine of crystal reports although am still hoping for a solution with what version I have.
0
 

Author Comment

by:techconcepts
Comment Utility
I have figured out with a little help from all of the above comments the solution to my problem.  Dick3425 was correct with saying the format must be converted to yyyy mm dd.  DRRYAN3 was also correct with first needing to format the date so that CRW understands it properly. I finally called crystal decisions and with their help was able to pass an exact date criteria to crystal reports. This was fine, but I still needed to be able to pick a date and send it to my report as a variable. The following code is the solution that works if you are interested.

first I stored the value of the 2 date picker controls into  variables that were dim'ed as strings. Then I formated the output that crystal reports could understand

BegDate = StartDT.Value
EndDate = EndDT.Value
BegDate = Format(BegDate, "yyyy, mm, dd")
EndDate = Format(EndDate, "yyyy, mm, dd")

then i created the criteria string like this

Dim strSelectCriteria as String

strSelectCriteria = "{History.OrderDate} >=   DATE(" & BegDate & ") and_ {History.OrderDate} <=   DATE(" & EndDate & ")"

Then passed this to the report

Reports.SelectionFormula = strSelectCriteria

and ta da!!!!

Now my last probelm with this question,

What do I do with the points that I posted? Who should get them?
0
 
LVL 12

Expert Comment

by:DRRYAN3
Comment Utility
techconcepts

give them to me!

Just kidding.  You can either decide to

1.  Award all points to one expert by clicking on the accept comment as answer link
2.  Split the points between two experts by leaving a message in the community support area (http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt) describing what you want to do
3.  Award no points because you solved you own problem.  Leave a message in community support asking them to PAQ the question and return your points.
4.  Ask that your question be deleted.  I would ask that you not do this because it does contain information others might find useful.

Glad you got it working
DRRYAN3
0
 

Expert Comment

by:costello
Comment Utility
Setting up point split as requested here: http://www.experts-exchange.com/jsp/qShow.jsp?ta=commspt&qid=20161535

Reducing points to 50 and accepting dick3425's comment.

Techconcepts, you will still have to open a 50 points question for DRRYAN. Please post a link to this question in here, so that DRRYAN can put a comment in that question.

costello
Community Support Moderator~@ Experts-Exchange
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

772 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

10 Experts available now in Live!

Get 1:1 Help Now