Public Sub DisplayReport(ByVal mRepName As String, ByVal mstrW As String, Optional ByVal strPars As String = "")
Dim mRep As New CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim ConInfo As New CrystalDecisions.Shared.TableLogOnInfo
Dim paraValue As New CrystalDecisions.Shared.ParameterDiscreteValue
Dim currValue As New CrystalDecisions.Shared.ParameterValues
Dim mySubReportObject As CrystalDecisions.CrystalReports.Engine.SubreportObject
Dim mySubRepDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim i, x, z As Integer 'Some Counters
Try
' Load the report
'Need to add the report dll yet Nothing Works
Dim rep As New RSMReports.clsReports(mRepName)
mRep = rep.returnRep()
mRep.RecordSelectionFormula = mstrW
'SQL Server
ConInfo.ConnectionInfo.UserID = MyUserID Here
ConInfo.ConnectionInfo.Password = My Password Here
ConInfo.ConnectionInfo.ServerName = mdlGeneral.serverName 'Stored Server name taht the database is on (using SQL Server)
ConInfo.ConnectionInfo.DatabaseName = mdlGeneral.dbName '(Database to use on the Server)
For i = 0 To mRep.Database.Tables.Count() - 1
mRep.Database.Tables(i).ApplyLogOnInfo(ConInfo)
Next i
'Check for Subreprots
For i = 0 To mRep.ReportDefinition.Sections.Count - 1
For x = 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)
For z = 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
If strPars.Trim() <> String.Empty Then
Dim arPars As String() = strPars.Split("~")
Dim strVal As String()
For xx As Integer = 0 To arPars.GetUpperBound(0)
strVal = arPars(xx).Split("=")
paraValue.Value = strVal(1)
currValue = mRep.DataDefinition.ParameterFields(strVal(0)).CurrentValues
currValue.Add(paraValue)
mRep.DataDefinition.ParameterFields(xx).ApplyCurrentValues(currValue)
Next
End If
' 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