Link to home
Create AccountLog in
Avatar of FIM2003
FIM2003Flag for United States of America

asked on

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

Avatar of EYoung
EYoung
Flag of United States of America image

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.
Avatar of FIM2003

ASKER

I'm just trying to set the value of a text object in the report, not filter the data being displayed in the report.
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?
Avatar of FIM2003

ASKER

Nope, I'm trying to set the text of a text object, named txtProjectType, that is in the report to be equal to txtCRProjectType.
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.
Avatar of FIM2003

ASKER

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
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.
Avatar of FIM2003

ASKER

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
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.
Avatar of FIM2003

ASKER

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

OK.  Best of luck.
Avatar of Mike McCracken
Mike McCracken

What version of Crystal?

What other code are you using to call the report?

mlmcc
Avatar of FIM2003

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of FIM2003

ASKER

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

Avatar of FIM2003

ASKER

Found the problem with the PDF export. Thanks for the help!
Avatar of FIM2003

ASKER

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).
Avatar of FIM2003

ASKER

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

Thanks again!