Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a CR based on criteria from a form in VB

Status
Not open for further replies.

jodo

Programmer
Feb 18, 2002
42
US
Using CR V8.5, VB 6, and MSRDC1.Connect
I have a main form. The user selects criteria from the Main form which I had hoped to place into some sort of WHERE clause for populating a CR. I already have the CR built with all the fields I want. Now, how do I pass the criteria for the report. I have tried:

strSelectionFormula = "{TC_HISTORY3.CREATED} = Date(" & _
Format(frmMain.cbStartDate, "yyyy/mm/dd") & ")"to Date(" & _
Format(frmMain.cbStartDate, "yyyy/mm/dd") & ")"
frmMain.crptTCHistory.SelectionFormula = strSelectionFormula
frmMain.crptTCHistory.Action = 1

My report does generate; however, there is no data. When I leave the criteria out and just open the report via (frmMain.crptTCHistory.Action = 1) the report does open with all of the data.

Is there something special I have to do in CR. I have seen so many examples of this and it looks so easy, but it doesn't work for me.

One more thing. How does this parameter thing work?
strDate = "Date(" & Year(frmMain.cbStartDate) & "," & Month(frmMain.cbStartDate) & "," & Day(frmMain.cbStartDate) & ")"
frmMain.crptTCHistory.ParameterFields(0) = "StartDate;" & strDate & ";true"
frmMain.crptTCHistory.Action = 1

Can someone please help.
 
When you pass date literals to a CR formula they have to be in CR Date literal format:

Date (yyyy,mm,dd)

You haven't told us which integration method you are using, see faq149-237 . Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
I'm using OCX (Crystal32.ocx). And I am using the yyyy,mm,dd format. I finally figured out a way to get around this whole formatting issue. I had to create a function to transform the date that the user sees on the screen mm/dd/yyyy into yyyy,mm,dd. Then I pass this parameter into my CR. However, every example I've seen uses this. Why wouldn't this work for me?

strSelectionFormula = "{TC_HISTORY3.CREATED} in Date(" & _
Format(frmMain.cbStartDate, "yyyy/mm/dd") & ")"to Date(" & _
Format(frmMain.cbStartDate, "yyyy/mm/dd") & ")"
frmMain.crptTCHistory.SelectionFormula = strSelectionFormula
frmMain.crptTCHistory.Action = 1

Is it because the Date(...) transforms the formatting back into a mm/dd/yyyy format?

Ken, Thank you for your help!!
 
It looks to me like your code is formatting the string with slashes instead of commnas. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Ooops! It works now, how ignorant of me. Anyway, one more thing. When I supply a date range on the form of 01/01/2002 to 02/22/2002, I get back data for 01/01/2002 to 02/06/2002 only. I know there is data after the sixth. Do you know why this could be happening? I'm using a date picker as my supply source on the form.

Thank you.
 
I would test the same date range and other criteria within CR first. Can't think of why that wouldn't work. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top