Solved

filling fields from a form label in crystal reports

Posted on 2004-09-02
14
304 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
cannot connect to sqlserver 8 29
Sql server insert 13 31
How do sunrise and sunset times change with altitude 14 31
VB.NET 2008 Winforms Signing 13 19
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
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…

809 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