mpdillon
asked on
How to pass static values to a Crystal report
My program calculates several static values such as TotalPounds. The values are calculated by the porgram before the Crystal report is called. I want to diplay these calculated values in the Page header of the Crystal report. I have created Parameters in Crystal. When I try to assign my calculated values to the Cystal report Parameter, I receive an invalid index message. I have checked my spelling and even used copy and paste to enure there are no mistakes. In the example below the datatype is set to number.
While I was trying to solve this problem, I discovered that my table.count = 0. (cryRpt.Database.Tables.co unt = 0). Yet there are 4 tables in this report. See the code section.
When I preview the report in designer, it displays the correct data.
If I diplay the report programatically by skipping over the Paramater section, the report is blank. This is not suprising because the code skips over th LogonInfo section because its table count is zero.
Why isn't my code seeing the tables in the report?
While I was trying to solve this problem, I discovered that my table.count = 0. (cryRpt.Database.Tables.co
When I preview the report in designer, it displays the correct data.
If I diplay the report programatically by skipping over the Paramater section, the report is blank. This is not suprising because the code skips over th LogonInfo section because its table count is zero.
Why isn't my code seeing the tables in the report?
Dim cryRpt As New ReportDocument
'
Dim crtableLogoninfos As New TableLogOnInfos
Dim crtableLogoninfo As New TableLogOnInfo
Dim crConnectionInfo As New ConnectionInfo
Dim CrTables As Tables
Dim CrTable As Table
cryRpt.Load(Main.ReportFileString.ToString.Trim)
'
With crConnectionInfo
.ServerName = Main.ServerNameStringPublic
.DatabaseName = "GMF"
.UserID = "Reports"
.Password = "reports"
End With
'
CrTables = cryRpt.Database.Tables
For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next
cryRpt.SetParameterValue("TotalPounds", TotalPoundsInteger)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This is where i learnt how to do Crystal Reports in Visual Studio. Some great pointers/sample code: http://vb.net-informations.com/crystal-report/vb.net_crystal_reports_tutorials.htm
What version of Crystal?
mlmcc
mlmcc
ASKER
emoreau: You wrote a very good article. I will use the Text object in future reports.
tickett: Yeah, that is the same one I am using. Very thorough. Although I wish it would have included passing text objects as was explained in emoreau article. It is the same as passing parameters but for someone who know nothing about Crystal, I just didn't know it existed.
mlmcc: I am using visual Studio 2008. It is what ever version shipped with VS2008.
Update: The real problem with this report is that it does not want to "load" the project. After the load I cannot see any tables. Yet in design mode, the report works fine.
I would like to have understood why this occurred. I have built a second duplicate report and it works fine. But these are complicated and detailed reports. I hate to spend several hours recreating a report that I could have just fixed if I knew what was wrong.
Thanks everyone for you input.
tickett: Yeah, that is the same one I am using. Very thorough. Although I wish it would have included passing text objects as was explained in emoreau article. It is the same as passing parameters but for someone who know nothing about Crystal, I just didn't know it existed.
mlmcc: I am using visual Studio 2008. It is what ever version shipped with VS2008.
Update: The real problem with this report is that it does not want to "load" the project. After the load I cannot see any tables. Yet in design mode, the report works fine.
I would like to have understood why this occurred. I have built a second duplicate report and it works fine. But these are complicated and detailed reports. I hate to spend several hours recreating a report that I could have just fixed if I knew what was wrong.
Thanks everyone for you input.
ASKER
The solution pointed me to passing text objects but did not resolve why the report at run time does not see the database tables after it is loaded.