Link to home
Start Free TrialLog in
Avatar of eyoung
eyoung

asked on

How pass VB6 variable to Crystal Report 7

I have written a Visual Basic 6.0 program that prompts the user for some string information.  I want to pass that string information to a Crystal Report 7.0 report and have the report print the string information in the title of the report.

How do I pass a variable (string information) from VB to CR?

Thanks,
EYoung
Avatar of ndb
ndb

Add a Crystal reports control on a form.
Then place the following code:

****************

Private Sub cmdReport_Click()
    Dim varParams
   
    ReDim varParams(1)

        With CrystalReport1
            .Connect = conConnection.ConnectionString
            .Destination = crptToWindow
            .ParameterFields(0) = "IDNumb;" & ListView1.SelectedItem.SubItems(7) & ";True"
            .ParameterFields(1) = "ParNumb;" & ListView1.SelectedItem.SubItems(8) & ";True"
            .ReportFileName = App.Path & "\MetaLog.rpt"
            .Action = 1
        End With
End Sub

***************

IDNumb and ParNumb are names of Parameters in Crystal Reports.
I don't think that you can.
Don't dim varParams.
It is just something I used in my program. You don't need it.
You only need the part between the with statements.
Parameters to Crystal are send:
"<ParamName>;<ParamValue>"
Avatar of eyoung

ASKER

ndb,

In your statement:

..ParameterFields(0) = "IDNumb;" & ListView1.SelectedItem.SubItems(7) & ";True"

If I wanted to just send one value say "123" to the report, would the VB line read:

..ParameterFields(0) = "IDNumb;" & "123" & ";True"

If this is correct, is the "IDNumb" the name of the CR Parameter field?  Also, what is ";True" used for?

Thanks for the quick help,
Regards,
EYoung
Indeed. IDNumb is a CR Parameter field.
If you set False instead of True,
Crystal Reports will set 123 as default value but will still show the dialog to ask the parameter.
If you set it to True, Crystal reports doesn't show that dialog anymore and uses the given value.
Avatar of eyoung

ASKER

ndb,

Thanks.  That works.  Please convert your comment to an answer and I'll accept it.  

I will accept it when I get back to this office tomorrow. Off to the client to apply this answer.

Thanks again for the help and quickness of your response.

Regards,
EYoung
ASKER CERTIFIED SOLUTION
Avatar of ndb
ndb

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of eyoung

ASKER

Thanks ndb