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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date parameter From VB( Need Help !)

Status
Not open for further replies.

CurtR

Programmer
Aug 9, 2000
66
US
I have Been Trying to Get Cyrstal 7.o to except a date from VB .
I am creating A front end to Operate some 50 Crystal reports. THe data
is In Oracle 8i database. I used Crystal Report Control in VB.
Here is a portion of what I have:

Private Date1 as Date

If ChkDayFlow.Value = True Then
CrystalReport1.ReportFileName = "S:\CITECT\d-01_FEV_Daily_Flow"
CrystalReport1.ParameterFields(0) = "START;Date1;True"
CrystalReport2.Connect = "PWD = REPORTS"
CrystalReport2.PrintReport

Date1 is from a text Box .
If I Replace
CrystalReport1.ParameterFields(0) = "START;Date1;True"
with
CrystalReport1.ParameterFields(0) = "START;2001/01/03;True"
The reports run fine.
I have tried setting the format in Crystal of the Parameter to Date, Date/Time,String
And Everything Else I could think of. Why Will crystal Except The date from code but not from the text box, or for that matter input box or Calendar?
Thanks CurtR
 
Make sure your passing Date1 value is in the correct format to begin with. Message box it so you can view it at run time and make sure it's YYYY/MM/DD format.

Good Luck,
CrystalVisualBOracle :)
 
I have been at this for 2 days solid now. I sent the txtbox to a label not msgbox. and the format looks to be Ok. Actually I can make it anyway I want to see it. Just not the way Crystal wants to see it.
I have tried everything I can possibly think of. I have used parameters in Crystal of
String, Date, Date/Time. I have used used formulas to format the parameter field
and then based the record selection off that formula. nothing works.
The date field in the database is a date/time field.
I tried DATE.Field = {?START}+" 00:00:00.00" with START set as a string.
Type 2001/01/13 in the parameter (in Crystal) and the report runs.
Go to VB and send
CrystalReport1.ParameterFields(0)= "Start;2001/01/03;True"
And the report runs
send
CrystalReport1.ParameterFields(0)= "Start;date1;True"
even thought the Label box shows 2001/01/03
NO REPORT!!?
I can enter the date into the VB line
CrystalReport1.ParameterFields(0)= "Start;2001/01/03;True"
and the Report will run OK from VB
But no matter what, it will Not Take input from Calendar,InputBox, TextBox, Even Though The Label shows the date formatted as 2001/01/03.
I am lost and very Frustrated.
and glad it's Friday!
 
Tried that already.
But will try again.
Thanks For your Help!
 
Hi CurtR,

Since you are picking up the date value from the textbox what you could do is convert it explicitly to date before supplying to Crystal. And if this does not work, accept a string into crystal and then convert it to date within crystal.


-Shweta
 
I have tried so much over the past 2 days that I can not remember what I have tried.
I set the Parameter in the report to Date. I used a formula to convert the parameter to a date/time and then compared that to the date.Field. The report ran from Crystal.
I set date1 ( date from Text Box) to Private date1 As Date (also sent it to label to watch it) entered 2001/01/03 in to txtBox output to label was 01/03/2001. Report would not run.

Phase 2; set parameter to String. converted it to Date/Time Report ran from crystal.
Set VB date1 as String. No Report.

Phase3; Set Parameter to date. Used formula to convert Date.Field from Date/Time to Date. Based Record Selection Off this Formula. Again the report ran from Crystal.
IN VB Set Date1 back to DATE. No report!
Somewhere somehow I am missing something.

Entered dates into the VB ParameterFields line "START;01/03/2001;True"
Report Runs.

I swear some days this thing Just Plain Hates Me!

Any Suggestions are Greatly Appreciated as I am now past my deadline with this, MY FIRST VB project... Thanks Everyone Curt
 
Just for kicks try declaring your date1 publicly using Dim instead of Private. Let's make sure it can see the value of Date1 in the report. Trial and error sure does suck doesn't it? I had a separate issue a while back trying to send a date to crystal from vb to query against and oracle database. For some reason, it made me put it into Oracle format. I honestly don't think that you need to do that here but you could give that a try anyway. The format for Oracle dates is DD-MON-YYYY.
 
I will give that a try as soon as i get into work on Monday.
in mean time I came across this in the Help file that i was finally able to open ( it was never loaded with the program)

You may want to pass date or date range information from your Visual Basic application to the Crystal Report Engine for use in formulas, selection formulas, etc. Here is an example showing a way to do it successfully:

1 Start by opening a print job and assigning the print job handle to a variable.

JobHandle% = PEOpenPrintJob ("C:\CRW\CUSTOMER.RPT")

2 Create variables that hold the year, month, and day for both the start of the range and the end of the range.

StartYear$ = 1992
StartMonth$ = 01
StartDay$ = 01
EndYear$ = 1993
EndMonth$ = 12
EndDay$ = 31

3 Now build a string to pass to the record selection formula. This is done in two steps:

· First, build the starting and ending dates for the date range.

 Assign the starting date string to the variable StrtSelect$.

 Assign the ending date string to the variable EndSelect$.

StrtSelect$ = &quot;{filea.STARTDATE} < Date
(&quot; + StartYear$ + &quot;, &quot; + StartMonth$ + &quot;, &quot;
+ StartDay$ +&quot;)&quot;
EndSelect$ = &quot;{filea.ENDDATE} < Date
(&quot; + EndYear$ + &quot;, &quot; + EndMonth$ +
&quot;, &quot; + EndDay$ +&quot;)&quot;

· Second, build the selection formula using the StrtSelect$ and EndSelect$ variables.

Recselct$ = StrtSelect$ + &quot; AND &quot; + EndSelect$

4 Once your formula is built, set the record selection formula for the report.

RetCode% = PESetSelectionFormula
(JobHandle%, RecSelect$)

5 Finally, print the report.

RetCode% = PEStartPrintJob (JobHandle, 1)
RetCode% = PEClosePrintJob (JobHandle, 1)

6 Modify this code to fit your needs.

Anyone else that gets into this trouble I found an excellent book today from Osborne press &quot; The Complete Reference Crystal Reports 7. It covers a lot of life's mysteries dealing with crystal and with crystal w/VB.
thanks
Curt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top