adrianjohnson
asked on
Parameters to a Crystal Report
I have an app written in VB6, and a Crystal Report in version 8.5 . The report has some parameter fields, which when set up had some data attached. This is so the report can pass those parameters to a SQL Server 2000 Stored Procedure in order to get the data back. How do I pass new parameter values for those fields from my VB app?
I include References in my VB project to the Crystal Reports 8.5 Libary, and ActiveX Library. but unsure if I need any others, or if there is a better method. If this is a better way of doing it, please let me know. Also, please supply VB code.
I apologise if I've not explained this properly, so feel free to ask questions. I may also up the points, depending on the complexity of the answer etc.
Thanks alot, Adi
I include References in my VB project to the Crystal Reports 8.5 Libary, and ActiveX Library. but unsure if I need any others, or if there is a better method. If this is a better way of doing it, please let me know. Also, please supply VB code.
I apologise if I've not explained this properly, so feel free to ask questions. I may also up the points, depending on the complexity of the answer etc.
Thanks alot, Adi
Good guess but the format is a little different
IPRPT.ParameterFields(0) = "Parm1=2"
IPRPT.ParameterFields(0) = "ParmName;Value;True"
IPRPT.ParameterFields(0) = "Parm1;2;TRUE"
mlmcc
IPRPT.ParameterFields(0) = "Parm1=2"
IPRPT.ParameterFields(0) = "ParmName;Value;True"
IPRPT.ParameterFields(0) = "Parm1;2;TRUE"
mlmcc
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
A little clarification
The generic version
IPRPT.ParameterFields(0) = "ParmName;Value;True"
Example based on the supplied code.
IPRPT.ParameterFields(0) = "Parm1;2;TRUE"
mlmcc
The generic version
IPRPT.ParameterFields(0) = "ParmName;Value;True"
Example based on the supplied code.
IPRPT.ParameterFields(0) = "Parm1;2;TRUE"
mlmcc
The easiest way to run a crystal report from VB, and to set parameters is to use a Crystal Report Control. So, under the Project|Components, you should pick the Crystal Report Control (viewer, whatever).
Then, in your code you'd have something like:
Report1.ReportFile = "C:\Code\MyRpt.rpt"
Report1.StoredProcParams(0 ) = 123
Report1.StoredProcParams(1 ) = chr$(34) & "Jones" & chr$(34)
Report1.Action = 1
The first question is about the nature of the parameters you mentioned. In Crystal, there are two different kinds of parameters. If you based your report on a stored proc, and the stored proc has parameters, then Crystal Creates StoredProcParams, which can be set using the code above.
If the developer went into Crystal and declared some Parameters there, then as mentioned above, I think this is referenced by Report1.ParametersFields(0 )
My preference is not to work with Crystal's parameters, but only work with the ones generated for the Stored Procs Parameters. When filling these parameters, make sure that they are formatted appropriately for the type of database you're accessing. I wrapped the text parameter in double-quotes above, and the easiest way to do this is by appending the chr$(34).
Then, in your code you'd have something like:
Report1.ReportFile = "C:\Code\MyRpt.rpt"
Report1.StoredProcParams(0
Report1.StoredProcParams(1
Report1.Action = 1
The first question is about the nature of the parameters you mentioned. In Crystal, there are two different kinds of parameters. If you based your report on a stored proc, and the stored proc has parameters, then Crystal Creates StoredProcParams, which can be set using the code above.
If the developer went into Crystal and declared some Parameters there, then as mentioned above, I think this is referenced by Report1.ParametersFields(0
My preference is not to work with Crystal's parameters, but only work with the ones generated for the Stored Procs Parameters. When filling these parameters, make sure that they are formatted appropriately for the type of database you're accessing. I wrapped the text parameter in double-quotes above, and the easiest way to do this is by appending the chr$(34).
ASKER
Thanks for the code. Got the report to work now, thanks.
I'd try this:
IPRPT.ParameterFields(0) = "Parm1=2"
Where IPRPT is the name of the CR activeX control on the form and Parm1 is the name of the CR parmater. If you need to set another parmater it would be the same excpt use ParameterFields(1) and keep incrementing the value of ParameterFields for each parameter.