Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Trouble Passing Value from VB to Crystal Reports Report

Posted on 2010-11-08
18
Medium Priority
?
309 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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
 

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 101

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 101

Accepted Solution

by:
mlmcc earned 2000 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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 …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

618 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