External Reports


The previous example uses a report that is embedded in the application. Using an external report is just as easy.

First, you must prevent Visual Basic from embedding the report in the project. In Solution Explorer, select the report. Then in the Properties window, set the report’s Build Action property to None and set its Copy to Output Directory property to Copy if newer. Now, when you build the application, Visual Studio will copy the report file into the directory where it places the compiled application.

To load the report at runtime, set the CrystalReportViewer control’s ReportSource property to the report’s location, as shown in the following code:

  ' Attach the report to the CrystalReportViewer. Private Sub Form1_Load(ByVal sender As System.Object, _  ByVal e As System.EventArgs) Handles MyBase.Load     crvTestScores.ReportSource = Application.StartupPath & "\StudentTestScores.rpt" End Sub 

That’s all there is to it. Now, if you must modify the report, you can distribute the new report file and the application will load the new version. You can also build a library of report files and let the application load whichever reports the user wants to see.




Visual Basic 2005 with  .NET 3.0 Programmer's Reference
Visual Basic 2005 with .NET 3.0 Programmer's Reference
ISBN: 470137053
EAN: N/A
Year: 2007
Pages: 417

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net