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!

Passing DateTime Parameter to Crystal from VB

Status
Not open for further replies.

k9

Programmer
Oct 25, 2000
5
US
I am trying to pass the DateTime parameter to crystal from some VB code. The string is formated as "yyyy/mm/dd 12:00:00AM", I have tried many other ways. I really curious how to correctly pass the Date.

Kevin
 
What version of Crystal are you using? I am using CR8 and VB6. In CR8 you use the CR8 Automation server to talk to your crystal report from VB. You need to declare the CR8 component in your class module like below.

Global CA As CRPEAuto.Application
Global CR As CRPEAuto.Report
Global DbName As CRPEAuto.Database
Global DbTbls As CRPEAuto.DatabaseTables
Global DbTbl As CRPEAuto.DatabaseTable
Global CrystalParams As CRPEAuto.ParameterFieldDefinitions
Global CrystalParam As CRPEAuto.ParameterFieldDefinition
Global CrystalFormulaFlds As FormulaFieldDefinitions
Global CrystalFormulaFld As CRPEAuto.FormulaFieldDefinition

You need to declare the application ('CA'), report ('CR'),
the database ('DbName'), tables ('DbTbls'), etc.....

The parts of the above your going to use are the formula definitions.

In your report, create a formula with a space between two double quotes like this " ".

You will need to set your application and open your report before being able to pass it data:

Set CA = CreateObject("Crystal.CRPE.Application")
Set CR = CA.OpenReport(strRunReport)

Next set your Database and tables and logon to the server:

Set DbName = CR.Database
Set DbTbls = DbName.Tables
Set DbTbl = DbTbls.Item(1)
Call DbTbl.SetLogOnInfo(my.OraID, "", my.UserID, my.PassWord)

Now scroll through the formulas in your report and set the datetime into the formula's text property.See code below.

Set CrystalFormulaFlds = CR.FormulaFields
For Each CrystalFormulaFld In CrystalFormulaFlds
Select Case CrystalFormulaFld.Name
Case {@YourFormula}
CrystalFormulaFld.Text = VB datetime
End
Next

Next Preview your report.

CR.Preview

I hope this helps

 
Where is the report using the value?

The correct syntax for DateTime in Crystal is a function with 6 numeric arguments:

Date (yyyy,mm,dd,hh,mm,ss)


This will go into a formula field, selection formula or a crystal parameter value.

If however you are giving this to a stored procedure parameter I have heard that you use the same format, but pass it as a string.



Ken Hamady-
 
The report requires 2 DateTime parameters be passed to it. One beginning date and one ending date. I am using Crystal 8 and VB6. My code goes something like this:

CryRpt.ReportFileName = Report Name

CryRpt.ParameterFields(index) = "ParameterName;Parametervalue;True"

CryRpt.Action = 1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top