Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How To: Crystal Reports 2008 with .rpt file

Hi all,

I've got my CR2008 reporting system up and running, but I'm not using DataSets or XSD files.

I created a Windows form with a CrystalReportViewer control, and in run time I just have to set the report filename, the title and formulas (if any).

I have to questions:

1. Do you think I'll stomp into any limitation with this approach?

2. The Crystal Reports form is opening as a Modal form. How can I stop this from happening (the Modal property is read only)?

I'm using the following code:

Public Class ADAT_Crystal
 
    Private DBUserid As String = "sa"
    Private DBPassword As String = "XXYYZZ"
    Private rptPath As String = ""
    Private rptConnectionInfo As ConnectionInfo
    Private rptDocument As ReportDocument
    Private rptCrystalForm As CrystalForm
    Private SelectionString As String = ""
 
 
    Public Function LoadCrystal(ByRef oCompany As SAPbobsCOM.Company, ByRef oApplication As SAPbouiCOM.Application, _
            ByRef Titulo As String, ByRef ReportName As String, ByRef Parametros As String, ByRef Formulas As String) As Boolean
        LoadCrystal = False
 
        Try
            rptPath = sPath & "reports" & ReportName
 
            SelectionString = Formulas
 
            SetDBConnection(oApplication, oCompany)
 
            SetReportDocument(oApplication)
 
            SetDBLogonForReport(oApplication)
 
            SetCrystalForm(oApplication, Titulo)
 
            LoadCrystal = True
        Catch ex As Exception
 
        End Try
    End Function
 
 
    Private Sub SetDBConnection(ByRef oApplication As SAPbouiCOM.Application, ByRef oCompany As SAPbobsCOM.Company)
        Try
            rptConnectionInfo = New ConnectionInfo()
 
            rptConnectionInfo.DatabaseName = oCompany.CompanyDB
            rptConnectionInfo.UserID = DBUserid         ' GetDBUserdID()
            rptConnectionInfo.Password = DBPassword     ' GetDBUserPassword()
            rptConnectionInfo.ServerName = oCompany.Server
 
        Catch ex As Exception
            oApplication.StatusBar.SetText(TranslateStr(oApplication, Error_) & ex.Message)
        End Try
    End Sub
 
 
    Private Sub SetReportDocument(ByRef oApplication As SAPbouiCOM.Application)
        Try
            rptDocument = New ReportDocument
            rptDocument.Load(rptPath)
            rptDocument.DataDefinition.RecordSelectionFormula = SelectionString
 
        Catch ex As Exception
            oApplication.StatusBar.SetText(TranslateStr(oApplication, Error_) & ex.Message)
        End Try
    End Sub
 
 
    Private Sub SetDBLogonForReport(ByRef oApplication As SAPbouiCOM.Application)
        Try
            Dim myTables As Tables = rptDocument.Database.Tables
 
            For Each myTable As Table In myTables
                Dim myTableLogonInfo As TableLogOnInfo = myTable.LogOnInfo
                myTableLogonInfo.ConnectionInfo = rptConnectionInfo
                myTable.ApplyLogOnInfo(myTableLogonInfo)
            Next
        Catch ex As Exception
            oApplication.StatusBar.SetText(TranslateStr(oApplication, Error_) & ex.Message)
        End Try
    End Sub
 
 
    Private Sub SetCrystalForm(ByRef oApplication As SAPbouiCOM.Application, ByRef Titulo As String)
        Try
            rptCrystalForm = New CrystalForm()
 
            rptCrystalForm.Text = Titulo
 
 
            rptCrystalForm.oCrystalReportViewer.ReportSource = rptDocument
            rptCrystalForm.oCrystalReportViewer.Refresh()
            rptCrystalForm.ShowDialog()
 
        Catch ex As Exception
            oApplication.StatusBar.SetText(TranslateStr(oApplication, Error_) & ex.Message)
        End Try
    End Sub
End Class

Handling the PrintPreview click


                    Case "519"
                        Dim SelectionString As String = "{ONP.DocNum} = " & Trim(oForm.Items.Item("DocNum").Specific.Value) & ""
                        Dim oCrystal As New ADAT_Crystal
                        oCrystal.LoadCrystal(oCompany, oApplication, "Nota de Produção", "rptNotaProd.rpt", "", SelectionString)
                        Return False

Regards,

Vítor Vieira

Former Member
Former Member replied

Hi Vitor,

For Q 1--

The problem u could face is that the Report files (.rpt) should be in place, if the files are moved by some user we can have a "File not found" exception. So better to expose the rpt files and embed them, But another disadvantage with embedding them is that if the user just wanted to change the logo or a simple aligment we have to change that in the code and again execute the code and pack the add on again. If we use a phusical file the user can make small desig modifications.

For Q 2--

For the modal form BUG u need to open the form in another thread. U can find the solution in the previous thread itself for that problem. If not just tell me. I'll help u.

Hope this helps.. and thanks for the new thread.. ,

Vasu Natari.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question