Link to home
Start Free TrialLog in
Avatar of coletteck8
coletteck8

asked on

filling fields from a form label in crystal reports

i am new to using crystal reports in vb.net and am trying to make a simple report that display the text contained in label fields on a form i have. is there a way to do this? the data doesn't have to be from the DB. is there a way to say field = label.text
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

BTW, the best topic area for this question is:

https://www.experts-exchange.com/Databases/Crystal_Reports/

More expert Crystal people there.

Bob
Avatar of natloz
natloz

Set up Parameters on your report and the pass the parameter values to the report through code
Not to say that there aren't any here, though, just a higher probability of getting a quicker answer is all :)

Bob
Avatar of coletteck8

ASKER

i wasn't sure where to put the question, so thanks!
Yes, I understand, with so many topic areas, it is often a daunting task to decide :)

Bob
natloz,
i have the parameters setup on the report. still a bit confused however
if i have a form class that has label.text = class.applicant.name
and i want the report to show the name property from the label.text can you give me an example of how i would pass that to the report?
Sorry...that is C#....hold on.
ASKER CERTIFIED SOLUTION
Avatar of natloz
natloz

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
will this still work if i am not using the report viewer? i only want to print the report, not view it at all.
i see the website where you obtained the above code, but it doesn't really help me. for instance, i'm not sure what each of the objects does and should this code be placed in my form class or in the report?
This code would be placed in your forms code for example when a  button has been pushed.
You don't need to use the ReportViewer if you don't want to, parameters have nothing to do with the Viewer.
The important part is that you are passing the Parameters to the report before printing/viewing.

Do you know how to print a report using VB.NET code? If so, do something similar to what you see above up until the point of:

CrystalReportViewer.ReportSource = CR  <---Replace with your code for printing direct...passing CR as Report Source.
i'm getting invalid field name error beginning at this line
crParameterFieldLocation = crParameterFieldDefinitions.Item("StartDate")
    crParameterValues = crParameterFieldLocation.CurrentValues
    crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
StartDate should be an actual Parameter name that you have defined in your Crystal Report...

Whatever your parameters names are, these should be used in place of "StartDate"

for example...If you have a parameter named "PersonsName" on your report...

and you had a field on your form called txtPersonsName...

 crParameterFieldLocation = crParameterFieldDefinitions.Item("PersonsName")
    crParameterValues = crParameterFieldLocation.CurrentValues
    crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
    crParameterDiscreteValue.Value = txtPersonsName.text <------------------YOUR VALUE TO PASS
    crParameterValues.Add(crParameterDiscreteValue)
    crParameterFieldLocation.ApplyCurrentValues(crParameterValues)