Solved

filling fields from a form label in crystal reports

Posted on 2004-09-02
14
305 Views
Last Modified: 2010-04-24
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
0
Comment
Question by:coletteck8
  • 6
  • 5
  • 3
14 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11967420
BTW, the best topic area for this question is:

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

More expert Crystal people there.

Bob
0
 
LVL 7

Expert Comment

by:natloz
ID: 11967552
Set up Parameters on your report and the pass the parameter values to the report through code
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11967566
Not to say that there aren't any here, though, just a higher probability of getting a quicker answer is all :)

Bob
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:coletteck8
ID: 11967622
i wasn't sure where to put the question, so thanks!
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11967630
Yes, I understand, with so many topic areas, it is often a daunting task to decide :)

Bob
0
 

Author Comment

by:coletteck8
ID: 11968277
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?
0
 
LVL 7

Expert Comment

by:natloz
ID: 11968492
0
 
LVL 7

Expert Comment

by:natloz
ID: 11968499
Sorry...that is C#....hold on.
0
 
LVL 7

Accepted Solution

by:
natloz earned 100 total points
ID: 11968551
   Imports CrystalDecisions.CrystalReports.Engine
    Imports CrystalDecisions.Shared
    '
    ' Load the selected report file.
    '
    Dim CR As New ReportDocument
    CR.Load(strReportPath)
    '
    ' Declare the parameter related objects.
    '
    Dim crParameterDiscreteValue As ParameterDiscreteValue
    Dim crParameterFieldDefinitions As ParameterFieldDefinitions
    Dim crParameterFieldLocation As ParameterFieldDefinition
    Dim crParameterValues As ParameterValues
    '
    ' Get the report's parameters collection.
    '
    crParameterFieldDefinitions = CR.DataDefinition.ParameterFields
    '
    ' Set the first parameter
    ' - Get the parameter, tell it to use the current values vs default value.
    ' - Tell it the parameter contains 1 discrete value vs multiple values.
    ' - Set the parameter's value.
    ' - Add it and apply it.
    ' - Repeat these statements for each parameter.
    '
    crParameterFieldLocation = crParameterFieldDefinitions.Item("StartDate")
    crParameterValues = crParameterFieldLocation.CurrentValues
    crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
    crParameterDiscreteValue.Value = strStartDate <------------------YOUR VALUE TO PASS
    crParameterValues.Add(crParameterDiscreteValue)
    crParameterFieldLocation.ApplyCurrentValues(crParameterValues)
    '
    ' Set the Crytal Report Viewer control's source to the report document.
    '
    CrystalReportViewer.ReportSource = CR
0
 

Author Comment

by:coletteck8
ID: 11974683
will this still work if i am not using the report viewer? i only want to print the report, not view it at all.
0
 

Author Comment

by:coletteck8
ID: 11975110
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?
0
 
LVL 7

Expert Comment

by:natloz
ID: 11976157
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.
0
 

Author Comment

by:coletteck8
ID: 11976397
i'm getting invalid field name error beginning at this line
crParameterFieldLocation = crParameterFieldDefinitions.Item("StartDate")
    crParameterValues = crParameterFieldLocation.CurrentValues
    crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
0
 
LVL 7

Expert Comment

by:natloz
ID: 11976886
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)


0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question