Solved

VS 2008 and Crystal Reports Viewer

Posted on 2008-06-11
11
490 Views
Last Modified: 2013-11-26
I am developing an application in VB/VS2008 and am using Crystal Reports and the CR Report Viewer.  I am able to use the viewer on a form, and can pass parameters and get the report to load.  What I am wondering is, can I use a single Form/Viewer to view all reports in my application?  Or do I have to create a Form/Viewer for each report?  I have not been able to find any examples of how to programatically call the form passing variables, so that I can use the same viewer for any report.  My scenerio is to have a form open, clicking on a button will pass a parameter to the report, and open the selected report in the viewer.  I'd like to do this from many areas of the application, but don't want to have to create multiple forms with viewers.
0
Comment
Question by:sassymacke
  • 6
  • 4
11 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 21761058
a single form is OK. check "Testing your report" from http://www.emoreau.com/Entries/Articles/2006/09/Feeding-Crystal-Reports-from-your-application.aspx (in particular CrystalReportViewer1.ReportSource = mrptDoc)
0
 

Author Comment

by:sassymacke
ID: 21761243
Thanks emoreau.  I hate to be a bonehead, but which code goes into the viewer's form, and which goes into the form where I'm calling the report from?
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 21762218
download the sample code that goes with the article. everything is there. Basically, there is nothing into the viewer form.
0
 

Author Comment

by:sassymacke
ID: 21762372
Sometimes right in front of your nose is not close enough!  I'll try this code and post back in a few. Thanks.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 21762375
If that code is different from yours, post your code and we can try to help modify it.

mlmcc
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:sassymacke
ID: 21762511
This is what I have, but I can't get past the error that myCrystalReportViewer is not declaired.  That is the name of my viewer control on Form2.  This is the code on the other form.
Imports CrystalDecisions.CrystalReports.ViewerObjectModel

Imports CrystalDecisions.ReportSource

Imports CrystalDecisions.CrystalReports.Engine

Imports CrystalDecisions.Shared
 

Public Class RFI
 

    Private rptReport As New ReportDocument    
 

Private Sub SetDBLogonForReport(ByVal myConnectionInfo As ConnectionInfo, ByVal myReportDocument As ReportDocument)
 

        Dim myTables As Tables = myReportDocument.Database.Tables

        For Each myTable As CrystalDecisions.CrystalReports.Engine.Table In myTables

            Dim myTableLogonInfo As TableLogOnInfo = myTable.LogOnInfo

            myTableLogonInfo.ConnectionInfo = myConnectionInfo

            myTable.ApplyLogOnInfo(myTableLogonInfo)

        Next
 

    End Sub

    Private Sub ConfigureCrystalReports()

        Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()
 

        myConnectionInfo.DatabaseName = "FrerichsPMgr"

        myConnectionInfo.IntegratedSecurity = True

        SetDBLogonForReport(myConnectionInfo, rptReport)

    End Sub

    Private Sub PrintPreviewToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintPreviewToolStripMenuItem1.Click

        Me.Cursor = Cursors.WaitCursor
 

        rptReport.Load("..\Reports\RFIRPT.rpt")
 

        ConfigureCrystalReports()

        

        Dim ID As String

        ID = Me.RFIIDTextBox.Text

        'Set the values of the parameters

        rptReport.SetParameterValue("RFIID", ID)
 

        'Pass the Report Document object to the viewer

        myCrystalReportViewer.ReportSource = rptReport

    End Sub

End Class

Open in new window

0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 21762606
myCrystalReportViewer has to be the name of your CR viewer.

Is it on the same form where this code runs?
0
 

Author Comment

by:sassymacke
ID: 21762656
That is the name of my viewer, but it is on a different form.  I want to call that form to open with the viewer when I press the button.  
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 21762750
Then you need to do something like:

dim f as new FormWithTheCRViewer
f.myCrystalReportViewer.ReportSource = rptReport
f.show
0
 

Author Comment

by:sassymacke
ID: 21762920
It WORKED!!!!  I have spent more time on this than I care to admit.  Thanks so much for the assitance!!!
0
 

Author Closing Comment

by:sassymacke
ID: 31466121
Thanks so much!!!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Help with checking if excel exist in client's computer 9 36
Where to begin studying? 5 64
.NET Error 7 42
Getfiles in vb.net 21 12
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now