I have four crystal reports already created. I want to incorporate those reports into an application whereby when a user clicks on a menu item the report opens in a new tab providing that it is not opended already.

i would be grateful if i can have some insight from someone thanks in advance.

I found it interesting so worked on it.
fill it with your report paths and see the result...
its working here..lemme know

Imports CrystalDecisions

Public Class Form1

    'assuming you have three reports medical,science and chemistry

    Private mediflag As Boolean = False
    Private sciflag As Boolean = False
    Private chemflag As Boolean = False

    Private Sub create_tab(name As String) ' this is for creting new tabs
        TabControl1.TabPages.Add(name, name)
        TabControl1.SelectedIndex = (Convert.ToInt16(TabControl1.TabPages.Count - 1))

        'placing report viewer in the selected tab and setting repoert viewer properties

        Dim repoertviewer As New Windows.Forms.CrystalReportViewer
        repoertviewer.ShowGroupTreeButton = False
        repoertviewer.Dock = DockStyle.Fill
        TabControl1.SelectedTab.Controls.Add(repoertviewer)

        Select Case name      'placing report viewer in thetab
            Case "Medical Report"
                'repoertviewer.ReportSource= report path here
            Case "Science Report"
                'repoertviewer.ReportSource= report path here
            Case "Chemistry Report"
                'repoertviewer.ReportSource= report path here
        End Select
    End Sub


    Private Sub place_report_viewer()

    End Sub



    'this is for closeing active tab/report

    Private Sub close_report_Click(sender As System.Object, e As System.EventArgs) Handles Btn_close_report.Click

        If TabControl1.TabPages.Count <> 0 Then

            Dim tabname As String = TabControl1.SelectedTab.Name.ToString

            Select Case tabname
                Case "Medical Report"
                    mediflag = False
                Case "Science Report"
                    sciflag = False
                Case "Chemistry Report"
                    chemflag = False
            End Select

            TabControl1.TabPages.Remove(TabControl1.SelectedTab)
        End If

    End Sub


    Private Sub focus_tab(name As String)  ' this will switch to the tab if it exists already
        TabControl1.SelectTab(name)
    End Sub




    Private Sub btn_medical_click(sender As System.Object, e As System.EventArgs) Handles btn_medical.Click

        'opening medical tab

        If Not mediflag Then
            create_tab("Medical Report")
            mediflag = True

        Else
            focus_tab("Medical Report") ' tab already existes...switching to tab
        End If



    End Sub


    Private Sub btn_science_Click(sender As System.Object, e As System.EventArgs) Handles btn_science.Click

        'opening science tab

        If Not sciflag Then
            create_tab("Science Report")
            sciflag = True

        Else
            focus_tab("Science Report") ' tab already existes...switching to tab
        End If
    End Sub



    Private Sub btn_chemistry_Click(sender As System.Object, e As System.EventArgs) Handles btn_chemistry.Click

        'opening chemistry tab

        If Not chemflag Then
            create_tab("Chemistry Report")
            chemflag = True

        Else
            focus_tab("Chemistry Report") ' tab already existes...switching to tab
        End If

    End Sub
End Class

i did some modifications but the core concept provided worked. However when it reports loads it is requesting a Database login i am looking for a way to not bring that up maybe by supplying the user windows login details....

any ideas would be greatful


I found it interesting so worked on it.
fill it with your report paths and see the result...
its working here..lemme know

Imports CrystalDecisions

Public Class Form1

    'assuming you have three reports medical,science and chemistry

    Private mediflag As Boolean = False
    Private sciflag As Boolean = False
    Private chemflag As Boolean = False

    Private Sub create_tab(name As String) ' this is for creting new tabs
        TabControl1.TabPages.Add(name, name)
        TabControl1.SelectedIndex = (Convert.ToInt16(TabControl1.TabPages.Count - 1))

        'placing report viewer in the selected tab and setting repoert viewer properties

        Dim repoertviewer As New Windows.Forms.CrystalReportViewer
        repoertviewer.ShowGroupTreeButton = False
        repoertviewer.Dock = DockStyle.Fill
        TabControl1.SelectedTab.Controls.Add(repoertviewer)

        Select Case name      'placing report viewer in thetab
            Case "Medical Report"
                'repoertviewer.ReportSource= report path here
            Case "Science Report"
                'repoertviewer.ReportSource= report path here
            Case "Chemistry Report"
                'repoertviewer.ReportSource= report path here
        End Select
    End Sub


    Private Sub place_report_viewer()

    End Sub



    'this is for closeing active tab/report

    Private Sub close_report_Click(sender As System.Object, e As System.EventArgs) Handles Btn_close_report.Click

        If TabControl1.TabPages.Count <> 0 Then

            Dim tabname As String = TabControl1.SelectedTab.Name.ToString

            Select Case tabname
                Case "Medical Report"
                    mediflag = False
                Case "Science Report"
                    sciflag = False
                Case "Chemistry Report"
                    chemflag = False
            End Select

            TabControl1.TabPages.Remove(TabControl1.SelectedTab)
        End If

    End Sub


    Private Sub focus_tab(name As String)  ' this will switch to the tab if it exists already
        TabControl1.SelectTab(name)
    End Sub




    Private Sub btn_medical_click(sender As System.Object, e As System.EventArgs) Handles btn_medical.Click

        'opening medical tab

        If Not mediflag Then
            create_tab("Medical Report")
            mediflag = True

        Else
            focus_tab("Medical Report") ' tab already existes...switching to tab
        End If



    End Sub


    Private Sub btn_science_Click(sender As System.Object, e As System.EventArgs) Handles btn_science.Click

        'opening science tab

        If Not sciflag Then
            create_tab("Science Report")
            sciflag = True

        Else
            focus_tab("Science Report") ' tab already existes...switching to tab
        End If
    End Sub



    Private Sub btn_chemistry_Click(sender As System.Object, e As System.EventArgs) Handles btn_chemistry.Click

        'opening chemistry tab

        If Not chemflag Then
            create_tab("Chemistry Report")
            chemflag = True

        Else
            focus_tab("Chemistry Report") ' tab already existes...switching to tab
        End If

    End Sub
End Class

lemme know if this helps :

Imports CrystalDecisions
 
Public Class Form1
 
    'assuming you have three reports medical,science and chemistry
 
    Private mediflag As Boolean = False
    Private sciflag As Boolean = False
    Private chemflag As Boolean = False
 
    Private Sub create_tab(name As String) ' this is for creting new tabs
        TabControl1.TabPages.Add(name, name)
        TabControl1.SelectedIndex = (Convert.ToInt16(TabControl1.TabPages.Count - 1))
 
        'placing report viewer in the selected tab and setting repoert viewer properties
 
        Dim repoertviewer As New Windows.Forms.CrystalReportViewer
        repoertviewer.ShowGroupTreeButton = False
        repoertviewer.Dock = DockStyle.Fill
        TabControl1.SelectedTab.Controls.Add(repoertviewer)


        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


        With crConnectionInfo
            .ServerName = "YOUR SERVER NAME"
            .DatabaseName = "YOUR DATABASE NAME"
            .UserID = "YOUR DATABASE USERNAME"
            .Password = "YOUR DATABASE PASSWORD"
        End With


        Select Case name      'placing report viewer in thetab
            Case "Medical Report"
                   cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\medicalreport.rpt")
            Case "Science Report"
                   cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\sciencereport.rpt")
            Case "Chemistry Report"
                   cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\chemistryreport.rpt")
        End Select


        CrTables = cryRpt.Database.Tables
        For Each CrTable In CrTables
            crtableLogoninfo = CrTable.LogOnInfo
            crtableLogoninfo.ConnectionInfo = crConnectionInfo
            CrTable.ApplyLogOnInfo(crtableLogoninfo)
        Next
 
        repoertviewer.ReportSource= cryRpt


    End Sub
 
  
    'this is for closeing active tab/report
 
    Private Sub close_report_Click(sender As System.Object, e As System.EventArgs) Handles Btn_close_report.Click
 
        If TabControl1.TabPages.Count <> 0 Then
 
            Dim tabname As String = TabControl1.SelectedTab.Name.ToString
 
            Select Case tabname
                Case "Medical Report"
                    mediflag = False
                Case "Science Report"
                    sciflag = False
                Case "Chemistry Report"
                    chemflag = False
            End Select
 
            TabControl1.TabPages.Remove(TabControl1.SelectedTab)
        End If
 
    End Sub
 
 
    Private Sub focus_tab(name As String)  ' this will switch to the tab if it exists already
        TabControl1.SelectTab(name)
    End Sub
 
 
 
 
    Private Sub btn_medical_click(sender As System.Object, e As System.EventArgs) Handles btn_medical.Click
 
        'opening medical tab
 
        If Not mediflag Then
            create_tab("Medical Report")
            mediflag = True
 
        Else
            focus_tab("Medical Report") ' tab already existes...switching to tab
        End If
 
 
 
    End Sub
 
 
    Private Sub btn_science_Click(sender As System.Object, e As System.EventArgs) Handles btn_science.Click
 
        'opening science tab
 
        If Not sciflag Then
            create_tab("Science Report")
            sciflag = True
 
        Else
            focus_tab("Science Report") ' tab already existes...switching to tab
        End If
    End Sub
 
 
 
    Private Sub btn_chemistry_Click(sender As System.Object, e As System.EventArgs) Handles btn_chemistry.Click
 
        'opening chemistry tab
 
        If Not chemflag Then
            create_tab("Chemistry Report")
            chemflag = True
 
        Else
            focus_tab("Chemistry Report") ' tab already existes...switching to tab
        End If
 
    End Sub
End Class

my application works like this: if the user double clicks on a node in a tree view the report loads. this issue i am having is that all users have access to the database via windows authentication, hence i did this

rpviewer.LogOnInfo.Item(0).ConnectionInfo.ServerName = GServer
                rpviewer.LogOnInfo.Item(0).ConnectionInfo.DatabaseName = GDatabase
                rpviewer.LogOnInfo.Item(0).ConnectionInfo.IntegratedSecurity = True

but i am getting a error.

i was wondering if you would take a look. regards

Imports CrystalDecisions
Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.ReportSource

Imports System.IO.Ports
 

'@@@@@@@@@@@@ Designed by: Travis Ferreira @@@@@@@@@@
'@@@@@@@@@@@@ Purpose:The purpose of this class is to house those
'@@@@@@@@@@@@ functions and subroutines which will aid in report generation
'@@@@@@@@@@@@ 

Public Class ReportingClass
    Dim repath As String = ""
    Dim rpviewer As New Windows.Forms.CrystalReportViewer



    Public Sub ReportControl(ByVal tellernum As Byte, ByVal rpnode As String)
        Select Case tellernum
            Case 0
                'doing nothing
            Case 1
            Case 2
            Case 3
            Case 4
            Case 5
            Case 6
                '###################################################################################
            Case 7
                If rpnode = "Transaction by Type\Receipts from Currency" Then
                    repath = INI.ReadString("REPORTS", "Teller7_Currencyreceipts")

                    If ValidatePath(repath) = True Then
                        Call LoadReport(repath, "Receipts from Currency")
                    Else
                        'message
                    End If
                    ' MsgBox(FrmTellersMDI.TreeViewREP.SelectedNode.FullPath())
                ElseIf rpnode = "Transaction by Type\Cheque Encashment" Then
                    repath = INI.ReadString("REPORTS", "Teller7_Cheque_Encashment")

                    If ValidatePath(repath) = True Then
                        Call LoadReport(repath, "Cheque Encashment")
                    Else
                        'message
                    End If
                    ' MsgBox(FrmTellersMDI.TreeViewREP.SelectedNode.FullPath())

                ElseIf rpnode = "Transaction by Type\Cash Deposits" Then
                    repath = INI.ReadString("REPORTS", "Teller7_CashDeposits")

                    If ValidatePath(repath) = True Then
                        Call LoadReport(repath, "Cash Deposits")
                    Else
                        'message
                    End If
                    ' MsgBox(FrmTellersMDI.TreeViewREP.SelectedNode.FullPath())
                Else

                End If
                '###################################################################################
            Case 8

        End Select
    End Sub
    Public Sub LoadReport(ByVal rpath As String, ByVal tabname As String)
        
        Try
            If VerifyTab(tabname) = True Then
                FrmTellersMDI.ReportTabControl.SelectTab(tabname)
            Else
                FrmTellersMDI.ReportTabControl.TabPages.Add(tabname, tabname)
                FrmTellersMDI.ReportTabControl.SelectedIndex = (Convert.ToInt16(FrmTellersMDI.ReportTabControl.TabPages.Count - 1))
                rpviewer = New Windows.Forms.CrystalReportViewer
                rpviewer.ShowGroupTreeButton = True
                rpviewer.ShowCloseButton = True
                rpviewer.Dock = DockStyle.Fill
                FrmTellersMDI.ReportTabControl.SelectedTab.Controls.Add(rpviewer)
                'rpviewer.LogOnInfo.Item(0).ConnectionInfo.ServerName = GServer
               ' rpviewer.LogOnInfo.Item(0).ConnectionInfo.DatabaseName = GDatabase
               ' rpviewer.LogOnInfo.Item(0).ConnectionInfo.IntegratedSecurity = True

                rpviewer.ReportSource = rpath
            End If



        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Function VerifyTab(ByVal tabname As String) As Boolean

        For Each page As TabPage In FrmTellersMDI.ReportTabControl.TabPages
            If page.Name = tabname Then
                Return True
            End If
        Next page
        Return False
    End Function


    Function ValidatePath(ByVal rpath As String) As Boolean


        If Len(rpath) = 0 Then
            Return False
        Else
            Return True
        End If
    End Function
End Class

lemme know if this helps :

Imports CrystalDecisions
 
Public Class Form1
 
    'assuming you have three reports medical,science and chemistry
 
    Private mediflag As Boolean = False
    Private sciflag As Boolean = False
    Private chemflag As Boolean = False
 
    Private Sub create_tab(name As String) ' this is for creting new tabs
        TabControl1.TabPages.Add(name, name)
        TabControl1.SelectedIndex = (Convert.ToInt16(TabControl1.TabPages.Count - 1))
 
        'placing report viewer in the selected tab and setting repoert viewer properties
 
        Dim repoertviewer As New Windows.Forms.CrystalReportViewer
        repoertviewer.ShowGroupTreeButton = False
        repoertviewer.Dock = DockStyle.Fill
        TabControl1.SelectedTab.Controls.Add(repoertviewer)


        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


        With crConnectionInfo
            .ServerName = "YOUR SERVER NAME"
            .DatabaseName = "YOUR DATABASE NAME"
            .UserID = "YOUR DATABASE USERNAME"
            .Password = "YOUR DATABASE PASSWORD"
        End With


        Select Case name      'placing report viewer in thetab
            Case "Medical Report"
                   cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\medicalreport.rpt")
            Case "Science Report"
                   cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\sciencereport.rpt")
            Case "Chemistry Report"
                   cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\chemistryreport.rpt")
        End Select


        CrTables = cryRpt.Database.Tables
        For Each CrTable In CrTables
            crtableLogoninfo = CrTable.LogOnInfo
            crtableLogoninfo.ConnectionInfo = crConnectionInfo
            CrTable.ApplyLogOnInfo(crtableLogoninfo)
        Next
 
        repoertviewer.ReportSource= cryRpt


    End Sub
 
  
    'this is for closeing active tab/report
 
    Private Sub close_report_Click(sender As System.Object, e As System.EventArgs) Handles Btn_close_report.Click
 
        If TabControl1.TabPages.Count <> 0 Then
 
            Dim tabname As String = TabControl1.SelectedTab.Name.ToString
 
            Select Case tabname
                Case "Medical Report"
                    mediflag = False
                Case "Science Report"
                    sciflag = False
                Case "Chemistry Report"
                    chemflag = False
            End Select
 
            TabControl1.TabPages.Remove(TabControl1.SelectedTab)
        End If
 
    End Sub
 
 
    Private Sub focus_tab(name As String)  ' this will switch to the tab if it exists already
        TabControl1.SelectTab(name)
    End Sub
 
 
 
 
    Private Sub btn_medical_click(sender As System.Object, e As System.EventArgs) Handles btn_medical.Click
 
        'opening medical tab
 
        If Not mediflag Then
            create_tab("Medical Report")
            mediflag = True
 
        Else
            focus_tab("Medical Report") ' tab already existes...switching to tab
        End If
 
 
 
    End Sub
 
 
    Private Sub btn_science_Click(sender As System.Object, e As System.EventArgs) Handles btn_science.Click
 
        'opening science tab
 
        If Not sciflag Then
            create_tab("Science Report")
            sciflag = True
 
        Else
            focus_tab("Science Report") ' tab already existes...switching to tab
        End If
    End Sub
 
 
 
    Private Sub btn_chemistry_Click(sender As System.Object, e As System.EventArgs) Handles btn_chemistry.Click
 
        'opening chemistry tab
 
        If Not chemflag Then
            create_tab("Chemistry Report")
            chemflag = True
 
        Else
            focus_tab("Chemistry Report") ' tab already existes...switching to tab
        End If
 
    End Sub
End Class
This article has been dead for over six months. Start a new discussion instead.