Trouble Passing Value from VB to Crystal Reports Report

I'm using the following code but the value isn't appearing in the report.

txtCRProjectType is getting the value I can see when debugging but txtProjectType is always blank in the report.
Dim txtCRProjectType As CrystalDecisions.CrystalReports.Engine.TextObject
txtCRProjectType = CType(report.ReportDefinition.ReportObjects.Item("txtProjectType"), CrystalDecisions.CrystalReports.Engine.TextObject)

txtCRProjectType.Text = txtCRProjectType.Text + myRow(dstProj.Tables("Type").Columns("Description")).ToString

Open in new window

FIM2003Asked:
Who is Participating?
 
mlmccCommented:
As soon as you REFRESH the report, the text field also refreshes so you lose the value.

Try moving the line so it is after the refresh

mlmcc
0
 
EYoungCommented:
Here is a link that might help.
http://vb.net-informations.com/crystal-report/vb.net_crystal_report_parameter_string.htm

The other suggestion is to re-write the report in MS SSRS.  SSRS is much easier to use and has none of the .dll problems that CR has.

Best of luck.
0
 
FIM2003Author Commented:
I'm just trying to set the value of a text object in the report, not filter the data being displayed in the report.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
EYoungCommented:
It sounds like from your original question that the CR report is not receiving the passed parm.  Have you tried to just print the parm in the header of the CR to verify?
0
 
FIM2003Author Commented:
Nope, I'm trying to set the text of a text object, named txtProjectType, that is in the report to be equal to txtCRProjectType.
0
 
EYoungCommented:
I would try printing the passed parm with a preceeding character, i.e. "/" and a following character, i.e. "/" to confirm the parm is being passed.  I don't think the parm value is being passed correctly to the report.

For example, if the passed parm is "ABC", then display just the passed parm in the report header with the preceeding and following character "/".  It should show up in the header as "/ABC/".  If it shows up as "//", then the parm value is not being passed to the report.
0
 
FIM2003Author Commented:
I'm not passing any parameters if you mean how I think you do. txtProjectType isn't a parameter field. It's a blank text object. But I just tried the code below and it didn't change anything.


txtCRProjectType.Text = "/" + txtCRProjectType.Text + myRow(dstProj.Tables("Type").Columns("Description")).ToString + "/"

Open in new window

txtprojecttype.png
0
 
EYoungCommented:
1.  "Trouble Passing Value from VB to Crystal Reports Report" is the title of your question so I thought you were trying to pass a parm value from VB to a CR report.  If you are trying to pass a value from a VB program to a CR report, I would suggest using the link I provided above to do the passing.

2.  If you are not trying to pass a value from VB to a CR report, then could you explain what you are trying to do?

3.  It looks like you were trying to attach a file to your last post.  If yes, it did not come through.
0
 
FIM2003Author Commented:
Yes, I'm trying to pass a value (a string) to a blank label (text object) in the report. I have a string in VB that I need to display on the form. The code that I posted on the original post should be working according to examples I've found elsewhere but it's not.

Not sure how to make this any clearer. Looking at the code snippet should be explanatory of what I'm trying to do.
txtprojecttype.png
0
 
EYoungCommented:
If you want to pass a value from your VB code to a CR report, pass it as a parm from VB to CR.  That way it will be received in CR and you can print it to the right of your "Project Type" field on the report.
0
 
FIM2003Author Commented:
I know there's multiple ways to do it but I'd like to use version 2 from the site below (that matches my code in the original post).

http://vbcity.com/forums/t/73601.aspx

I'm going to be passing multiple strings to different text objects and this way is less clutter and easier to manage. I just need to figure out why it's not working with my code being nearly identical.

I have used the C# code below to accomplish the same thing successfully in a different project.


CrystalDecisions.CrystalReports.Engine.TextObject txtBox1 = ((CrystalDecisions.CrystalReports.Engine.TextObject)report.DetailSection5.ReportObjects["txtBox1"]);
txtBox1.Text = "X";

Open in new window

0
 
EYoungCommented:
OK.  Best of luck.
0
 
mlmccCommented:
What version of Crystal?

What other code are you using to call the report?

mlmcc
0
 
FIM2003Author Commented:
CR 2008, VB.NET 2.0

Here's the code that calls the report. Everything shows properly on the report but the text objects aren't being filled in. I've just attempted the one (txtProjectType) for now until I get it working to fill in the others.
Dim report As New ReportDocument
report.Load("CrystalReport1.rpt")

Dim txtCRProjectType As CrystalDecisions.CrystalReports.Engine.TextObject = CType(report.ReportDefinition.ReportObjects.Item("txtProjectType"), CrystalDecisions.CrystalReports.Engine.TextObject)
txtCRProjectType.Text = "test"

Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
Dim crParameterValues As ParameterValues = New ParameterValues()
Dim crParameterDiscreteValue As ParameterDiscreteValue = New ParameterDiscreteValue()

crParameterDiscreteValue.Value = CInt(strCPNum)
crParameterFieldDefinitions = report.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions.Item("strProjectNum")
crParameterValues = crParameterFieldDefinition.CurrentValues

crParameterValues.Clear()
crParameterValues.Add(crParameterDiscreteValue)
        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

report.SetDatabaseLogon("", "")
CrystalReportViewer1.ReportSource = report
CrystalReportViewer1.RefreshReport()

Open in new window

0
 
FIM2003Author Commented:
I removed the refresh altogether. It does appear in my CR Viewer now (which I won't have visible) but it doesn't appear in the PDF when exported.


report.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, True, "ProjectReport")

Open in new window

0
 
FIM2003Author Commented:
Found the problem with the PDF export. Thanks for the help!
0
 
FIM2003Author Commented:
Well, I thought I did. I don't understand why it will load in the CrystalReportsViewer but not in the exported PDF (both loading from the same report variable).
0
 
FIM2003Author Commented:
Found it... Variable was losing its value after the page loaded. OK I'm done, now! :P

Thanks again!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.