Hi,
I have created an application in VS2010 that will print several reports. Thanks to this forum (Ludek) and following documentation/links from this site I have managed to now by pass the password prompt by passing the password parameters in code. However, my next issue is how to select a report to view/print. This is the code I have;
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Public Class frmViewer
Inherits System.Windows.Forms.Form
' ''CR Variables
Dim crReportDocument As CrystalReport1
Dim crDriverReport As CRDriver
Dim crDatabase As Database
Dim crTables As Tables
Dim crTable As Table
Dim crTableLogOnInfo As TableLogOnInfo
Dim crConnectionInfo As ConnectionInfo
' This call is required by the designer.
InitializeComponent()
crReportDocument = New CrystalReport1()
crConnectionInfo = New ConnectionInfo()
With crConnectionInfo
.ServerName = "myserver"
.DatabaseName = "mydb"
.UserID = "user"
.Password = "pw"
End With
'Get the table information from the report
crDatabase = crReportDocument.Database
crTables = crDatabase.Tables
'Loop through all tables in the report and apply the connection
'information for each table.
For Each Me.crTable In crTables
crTableLogOnInfo = crTable.LogOnInfo
crTableLogOnInfo.ConnectionInfo = crConnectionInfo
crTable.ApplyLogOnInfo(crTableLogOnInfo)
Next
'Set the viewer to the report object to be previewed.
CrystalReportViewer1.ReportSource = crReportDocument
That works great! But I want the CrystalReportViewer1 to be able to print ANY report from several.Do I have to have a viewer form per report with the above code. My only idea is as follows using a public variable strReport which is set when a certain report is required and then a select case;
With crConnectionInfo
.ServerName = "myserver"
.DatabaseName = "mydb"
.UserID = "user"
.Password = "pw"
End With
Select Case strReport
Case Is = "Branch"
crReportDocument = New CrystalReport1()
crDatabase = crReportDocument.Database
crTables = crDatabase.Tables
For Each Me.crTable In crTables
crTableLogOnInfo = crTable.LogOnInfo
crTableLogOnInfo.ConnectionInfo = crConnectionInfo
crTable.ApplyLogOnInfo(crTableLogOnInfo)
Next
CrystalReportViewer1.ReportSource = crReportDocument
'************************************************************************************************
Case Is = "Driver"
crDriverReport = New CRDriver
crDatabase = crDriverReport.Database
crTables = crDatabase.Tables
For Each Me.crTable In crTables
crTableLogOnInfo = crTable.LogOnInfo
crTableLogOnInfo.ConnectionInfo = crConnectionInfo
crTable.ApplyLogOnInfo(crTableLogOnInfo)
Next
CrystalReportViewer1.ReportSource = crDriverReport
End Select
End Sub
Any ideas? thanks, Ian