Solved

Trouble Passing Value from VB to Crystal Reports Report

Posted on 2010-11-08
18
298 Views
Last Modified: 2012-05-10
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

0
Comment
Question by:FIM2003
  • 10
  • 6
  • 2
18 Comments
 
LVL 7

Expert Comment

by:EYoung
ID: 34088405
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
 

Author Comment

by:FIM2003
ID: 34088463
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
 
LVL 7

Expert Comment

by:EYoung
ID: 34088528
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
 

Author Comment

by:FIM2003
ID: 34088567
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
 
LVL 7

Expert Comment

by:EYoung
ID: 34088623
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
 

Author Comment

by:FIM2003
ID: 34088692
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
 
LVL 7

Expert Comment

by:EYoung
ID: 34088810
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
 

Author Comment

by:FIM2003
ID: 34088889
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
 
LVL 7

Expert Comment

by:EYoung
ID: 34088954
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:FIM2003
ID: 34093607
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
 
LVL 7

Expert Comment

by:EYoung
ID: 34094540
OK.  Best of luck.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 34096092
What version of Crystal?

What other code are you using to call the report?

mlmcc
0
 

Author Comment

by:FIM2003
ID: 34096168
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
 
LVL 100

Accepted Solution

by:
mlmcc earned 500 total points
ID: 34096396
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
 

Author Comment

by:FIM2003
ID: 34096787
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
 

Author Closing Comment

by:FIM2003
ID: 34097033
Found the problem with the PDF export. Thanks for the help!
0
 

Author Comment

by:FIM2003
ID: 34097409
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
 

Author Comment

by:FIM2003
ID: 34097577
Found it... Variable was losing its value after the page loaded. OK I'm done, now! :P

Thanks again!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

705 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now