Print Page | Close Window

Binding Variables to Crystal Reports

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Data Connectivity
Forum Discription: How to connect to data sources and export reports
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=2182
Printed Date: 01 May 2024 at 11:38pm


Topic: Binding Variables to Crystal Reports
Posted By: lnickol22
Subject: Binding Variables to Crystal Reports
Date Posted: 30 Jan 2008 at 10:35am

I am using VS 2005 and the report viewer that comes along with this software...

I am developing an application and have declared and assigned values to variables. I've created my report and added the viewer to my form. When I execute the application everything is working the viewer sees my report and I am able to print.

I was wondering how I can use the values stored in my variables, and have them display in my report textboxes?

This is what I've got so far...

Assume:
 - Form1 has textboxes
 - Form2 has accessed these textbox values and assigned them to variables.
 - The variables in Form2 are for test purposes assigned to label. When application is in running values for Form1 appear in the labels on Form2.
 - A report has been created and has a textbox field named txtFName
 - Report is named Employee_Profile.rpt
 - Form2 has a report viewer named CrystalReportViewer1

source code:

Public Class Form1
Inherits System.Windows.Forms.Form
Private SeeForm2 As New Form2(Me)

Private Sub cmdPrint_Click(ByVal sender...)Handles cmdPrint.Click
SeeForm2.Show()
End Sub

End Class

Public Class Form2
Inherits System.Windows.Forms.Form
Private callingForm as Form1

Public Sub New(ByVal newCallingForm as Form1)
MyBase.New()
InitializeComponent()
callingForm = newCallingForm
End Sub

Private Sub Form2_Load(ByVal sender As...)Handles MyBase.Load
Dim FName As String

FName = callingForm.txtFName.Text

'Testing purposes to see if values has been passed
'Me.lblFName.Text = FName

Employee_Profile1.DataDefinitions.FormulaFields{txtFName as String} = FName

End Sub

End Class

Results from Build...

3 Errors

Error1 - Property access must assign to the property or use its value.
Error2 - Expression expected {
Error3 - Method arguements must be enclosed in paretheses.


I'm sure the solution is right in front of my face, I'm just having troubles seeing it right now! Any help on this source code or further explinations would be appreciated... Thanks so much to those that have taken the time to read this - and are able to offer solutions.




-------------
Liz Nickol
GIS Assistant
Gwa'-sala - 'Nakwaxda'xw Nation



Replies:
Posted By: BrianBischof
Date Posted: 30 Jan 2008 at 11:30am
The problem is that you are assigning raw text to a CR formula and it doesn't know what to do with it. It doesn't realize that you are assigning a string constant to it. Thus, you have to surround FName with quotes and pass this to CR. Then it will know that this is a string constant. I don't understand the "txtFName as String" part either. Is this your actual code? Anyway, here you go:

Employee_Profile1.DataDefinitions.FormulaFields["your formula name here"] = (char)39 + FName + (char)39;



-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>



Print Page | Close Window