Solved

Retrieve records by date parameter

Posted on 2001-07-27
7
299 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6329020
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
ID: 6329123
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
ID: 6329191
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:techconcepts
ID: 6330013
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
ID: 6336130
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
ID: 6336582
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
ID: 6341037
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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. …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

733 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