Preeti
Preeti

Reputation: 1386

Passing Crystal Report name as parameter

I am using a function which is calling a crystal report as :

ShowReport ( Report1)

In show report ShowReport :

Dim repDoc As New Report1  **' here i am want to assign crytalReport name**
repDoc.SetDatabaseLogon("username", "*****")
CrystalReportViewer1.ReportSource = repDoc
CrystalReportViewer1.Visible = True

How can i do that ?

Upvotes: 0

Views: 1556

Answers (1)

Buck Hicks
Buck Hicks

Reputation: 1574

I have done something like this in the past that you may be able to use for your purposes. Normaly I use a Dropdown list or a Listbox to allow the user to select the file they want to view and then use pass the Item Index to the the intFileId.

Private Sub OpenCR(ByVal intfileId As Integer)
    Dim aReport As ReportDocument
    Select Case intfileId
        Case 0 : aReport = New CountSheets
        Case 1 : aReport = New CategoryVariance
        Case 2 : aReport = New DollarVariance
        Case 3 : aReport = New CategoryVarianceAdmin
        Case 4 : aReport = New DollarVarianceAdmin
        Case 5 : aReport = New PhysicalCount
        Case 6 : aReport = New BookToPhysicalCount
        Case 7 : aReport = New MissingItemCodes
    End Select

    aReport.Refresh()
    aReport.SetParameterValue("isAmtsShown", isAmtsShown)
    aReport.SetParameterValue("parStoreID", StoreID)
    aReport.SetDatabaseLogon("username", "password", "server", "table")
    crvReports.ReportSource = aReport

End Sub

To answer the specific question about passing the name as the argument. You could do it with something like this:

 Private Sub RunReportbyName()
    ' The Crystal Report name in
    ' this project is MyReport.rpt
    Dim aReport As ReportDocument = New MyReport
    OpenCR(aReport)
End Sub

Private Sub OpenCR(ByVal RepDoc As ReportDocument)
    'RepDoc.SetDatabaseLogon("","","","")
    CrystalReportViewer1.ReportSource = RepDoc
    CrystalReportViewer1.Visible = True

End Sub

Upvotes: 1

Related Questions