[RESOLVED] Pass Vb global variable to CR
I have a global variable that I want to use in all my CRs, its set when my main menu opens, works quite well and I have it as a title on all my forms. It is layed out like this. strTitle
ACME Housing Development
123 Any street
Some City, State, Zip
Phone 555-555-1212, Fax: 555-555-1313
John Doe Executive Director
Anyway I want to use that for the title of all my reports but I'm having trouble comprehending how to pass the variable to my report viewer and onto my report.
I've found a couple examples, and can't seem to get any of them to work.
If someone has a short example of how to pass the variable that would be great.
Thanks
LB
Re: Pass Vb global variable to CR
You didn't say CR version, anyway I'll assume that you are using RDC
You could do it using formula fields
In the rpt
Insert a formula field in the page header section, lets say @Title
Code:
Trim("Here goes title")
In vb6 code
(You need to reference Crystal ActiveX Report Viewer Library)
Code:
Dim MEnt1 As Integer
Dim CRApplication As New CRAXDRT.Application
Dim CRReport As New CRAXDRT.Report
'
'code goes here
'
Set CRReport = CRApplication.OpenReport("MyRpt.rpt", 1)
'
'
'
For MEnt1 = 1 To CRReport.FormulaFields.Count
Select Case CRReport.FormulaFields(MEnt1).name
Case "{@Title}"'this is name of the formula in CR
CRReport.FormulaFields(MEnt1).Text = "Trim(" & Chr(39) & "ACME Housing Development." & Chr(39) & ")"
Case "{@XXX}"
CRReport.FormulaFields(MEnt1).Text = "something else"
End Select
Next MEnt1
In vb.net code
Code:
'You need to declare variables and CR objects
For Ment1 = 0 To CRReport.DataDefinition.FormulaFields.Count - 1
Select Case CRReport.DataDefinition.FormulaFields.Item(CRCount).Name.ToString
Case "Title" : CRReport.DataDefinition.FormulaFields.Item(MEnt1).Text = "Trim(" & Chr(39) & "ACME Housing Development." & Chr(39) & ")"
Case "b" : CRReport.DataDefinition.FormulaFields.Item(MEnt1).Text = "any aother value"
End Select
Next MEnt1
This is an example in how to pass a text to a rpt using formula fields
Re: Pass Vb global variable to CR
Not sure about old versions but CR for 2010 has fields especially for that,
Quote:
Dim frm as New frmReports
Dim rpt As New GroupsByUserId
rpt.SummaryInfo.ReportTitle = clsCoInfo.CompName & vbNewLine & clsCoInfo.Address1
rpt.SummaryInfo.ReportComments = "What ever you want to say"
rpt.SummaryInfo.ReportAuthor = "report author"
rpt.SetDataSource(yourdatasource)
frm.CrystalReportViewer1.ReportSource = rpt
frm.ShowDialog()
Look in the Field Explored->Special Fields
Re: Pass Vb global variable to CR
Ah that's cool.
I ended up using this:
DepositDispositionRpt1.SetParameterValue("ReportHeading", strReportHeading)
strReportHeading being a global variable in my application
I'm sure going to give your example a try.
Thanks
LB