Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crystal Report text field 2

Status
Not open for further replies.

shiggyshag

Programmer
Dec 14, 2001
227
0
0
GB
HI

I have a simple Crystal Report with two TextObjects one is cSurname The other is cForename.
All i want to do is when I open it from a vb.net form is pass the values of the surname and forename that are on the vb.net form.

Please Help

Cheers
 
Look at CR Parameters.

Add 2 parameters to your Crystal Report, one for surname and one for forename. Position these onto your report, just drag and drop them, change fonts etc...

Then in your vb form, set the values of the parameters.

orpt.SetParameterValue("surname", "SMITH")
orpt.SetParameterValue("firstname", txtName.text)



Sweep
...if it works dont mess with it
 
Hi

Thank you for your help being this is the first time I have used crystal How do I add Parameters to the report?

Thank you

 
Hi

me again also SetParameterValue is not a member of the report

Cheers again
 
Under Field Explorer, which is the tree view for the database fields, formula fields etc...you will find Parameter Values.

Create your report, lets say its called cr1, and it exists in the same project as your form which you want to pass parameters from.

In your VB Form

Code:
Dim orpt As New cr1 'The name of the Report Created'
orpt.SetParameterValue("name", "Smith")


Sweep
...if it works dont mess with it
 
Hi

Done all you said but still says SetParameterValue is not a memeber of CR1

Cheers
 
I just created a new report, added 1 parameter, and could reference SetParameterValue through code as per previous post.

Have you remembered to save your report, before referencing it through code?

Have you imported the references required to Crystal in your project?. Right click References, add References, and add all the ones name beginning Crystal Decisions.



Sweep
...if it works dont mess with it
 
HI again

I have this code on a test Form

Public Class testForm
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
'
'testForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(544, 365)
Me.Name = &quot;testForm&quot;
Me.Text = &quot;testForm&quot;

End Sub

#End Region

Private Sub testForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim orpt As New CR1() 'The name of the Report Created'
orpt.SetParameterValue(&quot;name&quot;, &quot;Smith&quot;)
End Sub
End Class

I have a Report named CR1 with a parameter field named name but it still doesnt work

I have refernces to all the Crystal Decisions

Sorry to keep on

Cheers
 
The code below assumes the following:

1. you have a text object called foo in the report
2. the text object is in Section3 of your crystal report
3. You'll place this code before you set the report datasource and the crystal report viewer report source

Dim tmp As CrystalDecisions.CrystalReports.Engine.TextObject

tmp = crTraveler.ReportDefinition.Sections(&quot;Section3&quot;).ReportObjects.Item(&quot;foo&quot;)
tmp.Text = somevariable

Scott
Programmer Analyst
<{{><
 
Works great

Do you know if its possible to send a vaiable to an image on the report so it finds the correct picture?

Thankyou
 
stnkyminky,
I am trying to pass data to a text box on my crystal report from a form in vb.net. When I use the code you suggested, I get an error "'text' is not a member of 'CrystalDecisions.CrystalReports.Engine.ReportObject'."
The text box is on my crystal report. tmp is dim as a text object but is then being set to a report object. Have I left something out somewhere? What am I missing?
Thanks in advance for any help you can provide.
Diana
 
You don't need to use parameters for this. Consider the following code:

Code:
Dim TextField As CrystalDecisions.CrystalReports.Engine.TextObject
TextField = YourReportInstance.Section1.ReportObjects.Item(0)
TextField.Text = "Hello"

You declare a TextObject. You set it equal to an object in a section of your report. For example, if the field is in the report header, then that will most likely be section 1.
 
Dim TextField As CrystalDecisions.CrystalReports.Engine.TextObject
TextField = cr.PageHeaderSection1.ReportObjects.Item(0)
TextField.Text = cInvestigator.LocationName.ToString


Here is my code that I am using. I have a text box in the page header of my report. I want to pass "IGCN", in this case, to the text box to be displayed. I am still get the build error - (2173): Option Strict On disallows implicit conversions from 'CrystalDecisions.CrystalReports.Engine.ReportObject' to 'CrystalDecisions.CrystalReports.Engine.TextObject'.

If I go ahead and run the report, I get an error message "Specified Cast is not valid."

What am I doing wrong? In VB it was SetText and it worked great. I also tried instead of 0, putting the name of my text field("txtDO"). Still didn't like it.
Diana
 
Use this instead with Option Strict On

Code:
TextField = CType(cr.Section1.ReportObjects.Item(0), CrystalDecisions.CrystalReports.Engine.TextObject)
 
BTW,

I didn't see stnkyminky's post at first. I had never done it that way, but it does work. It works with option strict as well if you are sure to cast it explicitly.
 
I didn't have Option Strict On when I created/run the code above. You might want to remove this and see if it fixes your problem.

Scott
Programmer Analyst
<{{><
 
OK. It works. I knew I had to be doing something wrong. I had messed with the report so much, I didn't realize the object I thought was a text object was actually a field object. Thanks for your help. I knew this had to be easier than what I was trying to make it.
Diana
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top