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.count = 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?

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)

Open in new window

mpdillonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tickettCommented:
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
0
mlmccCommented:
What version of Crystal?

mlmcc
0
mpdillonAuthor Commented:
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.
0
mpdillonAuthor Commented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.