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

passing parameters from VB

Status
Not open for further replies.

wrbodine

Programmer
Aug 24, 2000
302
0
0
US
I'm wanting to know how to pass a parameter from VB6 to CR7. I've got some ideas about syntax on the VB side (possibly using CRAXDRT.ParameterFieldDefinition?), but don't have a clue of how to reference the parameter in the report, where it needs to be a part of a where sql clause. (I've checked Crystal's help and the old threads here and haven't seen anything useful yet).

TIA,
Ray
 
Here is some code to use. I found the example coding on page 95 of the CR Developer's Guide (v8) helpful also.


Dim x As Long
For x = 1 To crxrpt.ParameterFields.Count
Select Case crxrpt.ParameterFields.Item(x).Name
Case "{?Parameter1}"
crxrpt.ParameterFields.Item
(x).SetCurrentValue "Parmater 1 Value"
Case "{?Parameter2}"
crxrpt.ParameterFields.Item
(x).SetCurrentValue "Parmater 2 Value"
Case "{?Parameter3}"
crxrpt.ParameterFields.Item
(x).SetCurrentValue "Parmater 3 Value"
End Select
Next


...and so on. I hope this helps!
Brett Please visit my websites!
 
Thanks Brett,

I think this is on the right track... I'll have to play w/ it some more; right now I'm getting a type mismatch error, sending an integer parameter. But at least its recognizing my Crystal parameter in VB....

Thanks again,
Ray
 
I'm actually still having a problem with setCurrentValue : its giving a type mismatch error when I try and set the parameter value this way. I've tried a couple other ways as well... Any ideas?
 
The set current value required that you also pass the datatype of the parameter. Are you sure that you are doing this, and that the datatype is correct? Steven Fowler, Principal
steve.fowler@fowlerconsulting.com
- Development, Training, and Consulting
wpe1.gif
 
Thanks Steven,

I had noticed the need of that datatype value (I ended up using 7 for number). I also needed to cast the parameter to an int and recieve in in the report through the select expert instead of directly through SQL. So its working now...

Thanks,
Ray
 
This is really a good solution.
However when I export the report with parameters, I got run-time-error 20540 "missing or out-of-date export DLL". The error is on this statement- Call PcrpReport.Export(False)
But it ran smoothly to export other reports with no parameter by using this statement.
So, does anyone know which DLL I need to solve this problem?
Thanks!!

Below is my code:
=====================
Public POrID As String
Public POrcInst As String
Public POrcName As String
Public POrID2 As String
Public PConn As New ADODB.Connection
Public PcrpApplication As New CRPEAuto.Application
Public PcrpReport As CRPEAuto.Report
Public PcrpPageOptions As CRPEAuto.PageSetup
Public PcrpExportOptions As CRPEAuto.ExportOptions


Public Sub ExportReport()
Dim vRptName, PExpRptName As String
Dim VendorSQL As String
Dim VendorRS As New ADODB.Recordset
Dim x As Long

vRptName = "C:\CrystalTest\VendorReport.rpt"
Set PcrpReport = PcrpApplication.OpenReport (vRptName)

PcrpReport.Database.Tables(1).SetLogOnInfo POrcName, POrcInst,
POrID, POrID2

Set PcrpExportOptions = PcrpReport.ExportOptions
PcrpExportOptions.DestinationType = crEDTDiskFile

VendorSQL = "SELECT DISTINCT VendorCode, VendorName from Vendor "
VendorRS.Open VendorSQL, PConn, adOpenDynamic

Do While Not VendorRS.EOF
x = 1
For x = 1 To PcrpReport.ParameterFields.Count
Select Case PcrpReport.ParameterFields.Item(x).Name
Case "{?parAgentName}"
PcrpReport.ParameterFields.Item(x).SetCurrentValue
Trim(VendorRS!VendorName)
Case "{?Parameter2}"
crxrpt.ParameterFields.Item(x).SetCurrentValue
"Parmater 2 Value"
Case "{?Parameter3}"
crxrpt.ParameterFields.Item(x).SetCurrentValue
"Parmater 3 Value"
End Select
Next x

PExpRptName = "C:\CrystalTest\VendorReport" &
Trim(VendorRS!VendorCode) & ".rtf"
PcrpExportOptions.DiskFileName = PExpRptName
Call PcrpReport.Export(False)
VendorRS.MoveNext
Loop

Set PcrpReport = Nothing
Set PcrpExportOptions = Nothing
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top