Public Sub DisplayReport(ByVal mRepName As String, ByVal mstrW As String, Optional ByVal strTitle As String = "")
Dim mRep As New CrystalDecisions.CrystalReports.Engine.ReportDocument
'Dim tbCurrent As CrystalDecisions.CrystalReports.Engine.Table
Dim ConInfo As New CrystalDecisions.Shared.TableLogOnInfo
Dim paraValue As New CrystalDecisions.Shared.ParameterDiscreteValue
'Dim currValue As CrystalDecisions.Shared.ParameterValues
'Sub report object of crystal report.
Dim mySubReportObject As CrystalDecisions.CrystalReports.Engine.SubreportObject
'Sub report document of crystal report.
Dim mySubRepDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument
Try
' Load the report
mRep.Load(mRepName)
mRep.RecordSelectionFormula = mstrW
If strTitle <> String.Empty Then
mRep.SummaryInfo.ReportTitle = strTitle
End If
ConInfo.ConnectionInfo.DatabaseName = mdlGeneral.gstrFullDBInfo
For i As Integer = 0 To mRep.Database.Tables.Count() - 1
mRep.Database.Tables(i).ApplyLogOnInfo(ConInfo)
Next i
'Check for Subreprots
For i As Integer = 0 To mRep.ReportDefinition.Sections.Count - 1
For x As Integer = 0 To mRep.ReportDefinition.Sections(i).ReportObjects.Count - 1
With mRep.ReportDefinition.Sections(i)
If .ReportObjects(x).Kind = CrystalDecisions.Shared.ReportObjectKind.SubreportObject Then
mySubReportObject = CType(.ReportObjects(x), CrystalDecisions.CrystalReports.Engine.SubreportObject)
mySubRepDoc = mySubReportObject.OpenSubreport (mySubReportObject.SubreportName) <--Errors Here wirh Invalide table Number
For z As Integer = 0 To mySubRepDoc.Database.Tables.Count - 1
mySubRepDoc.Database.Tables(z).ApplyLogOnInfo(ConInfo)
Next z
End If
End With
Next x
Next i
' Set the report source for the crystal reports viewer to the report instance.
Me.crViewer.ReportSource = mRep
' Zoom viewer to fit to the whole page so the user can see the report
Me.crViewer.Zoom(100)
'Me.crViewer.ShowRefreshButton = False
Me.crViewer.DisplayGroupTree = False
Catch crExp As CrystalDecisions.CrystalReports.Engine.LoadSaveReportException
MessageBox.Show("Error printing Report " & mRepName & System.Environment.NewLine & _
"The error number is: " & Err.Number.ToString() & System.Environment.NewLine & _
"The error Message is: " & System.Environment.NewLine & crExp.Message.Trim(), "Print Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Catch ex As Exception
MessageBox.Show("Error printing Report " & mRepName & System.Environment.NewLine & _
"The error number is: " & Err.Number.ToString() & System.Environment.NewLine & _
"The error Message is: " & System.Environment.NewLine & ex.Message.Trim(), "Print Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub