Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace a database connection for report and all subreports

Is there is any way to change the datasource location for a report and all of it's subreports without having to open each of them manually?

like image 498
John Hubert Avatar asked Sep 02 '08 20:09

John Hubert


People also ask

How do you pass subreport value to main report?

To share values between a subreport and the main report in Crystal Reports, use shared variables. Using shared variables requires at least two formulas: One to store the value in a shared variable. Tthe other to retrieve the value from the shared variable.

What is the use of Subreports in Crystal Reports?

Subreports allow you to combine unrelated reports into a single report. It is a report within a report. You can combine data that cannot be linked and present different views of the same data in a single report.

How do you add a subreport to an existing report in Access?

In the Navigation Pane, right-click the report to which you want to add a subreport, and then click Design View. In the menu that appears, ensure that Use Control Wizards is selected. Open the Controls Gallery again, and then click Subform/Subreport. On the report, click where you want to place the subreport.

How to Access subreport field in main report?

Open the main report in design view. Right-click the edge of the subform control, and choose Properties. Check the Name of the subreport control (on the Other tab of the Properties box.) The Name of the subreport control can be different than the name of the report it contains (its Source Object.)


2 Answers

Here is how I set my connections at runtime. I get the connection info from a config location.

        #'SET REPORT CONNECTION INFO
        For i = 0 To rsource.ReportDocument.DataSourceConnections.Count - 1
            rsource.ReportDocument.DataSourceConnections(i).SetConnection(crystalServer, crystalDB, crystalUser, crystalPassword)
        Next

        For i = 0 To rsource.ReportDocument.Subreports.Count - 1
            For x = 0 To rsource.ReportDocument.Subreports(i).DataSourceConnections.Count - 1
                rsource.ReportDocument.OpenSubreport(rsource.ReportDocument.Subreports(i).Name).DataSourceConnections(x).SetConnection(crystalServer, crystalDB, crystalUser, crystalPassword)
            Next
        Next
like image 184
Jas Avatar answered Oct 03 '22 10:10

Jas


If you are just doing this as a one-shot deal, my suggestion might not help. But, if you change data sources frequently, it might be useful.

Disclaimer: I haven't worked with Crystal since version 9.0, so I don't know if they have improved on this. I always used UDL files. Basically, it is a pointer to a data source. Set up your report to point to the UDL, and the UDL points to the data source. If the source changes, just update the UDL.

This is incredibly useful if you have multiple reports. You only have to update one file when the server changes.

like image 25
Jason Z Avatar answered Oct 03 '22 10:10

Jason Z