Data Connectivity
 Crystal Reports Forum : Crystal Reports .NET 2003 : Data Connectivity
Message Icon Topic: Object reference not set to an instance of an obje Post Reply Post New Topic
Author Message
Dimitro
Newbie
Newbie
Avatar

Joined: 02 Aug 2014
Location: Indonesia
Online Status: Offline
Posts: 1
Quote Dimitro Replybullet Topic: Object reference not set to an instance of an obje
    Posted: 05 Aug 2014 at 11:19pm

Dear all experts  I’m a new bie in Crystal Report and I start to using Crystal Report for make a dynamic report, my problem is I am getting an Object reference not set to an instance of an object when Crystal Report View assigned as Report Document, but the report is shown successfully under Crystal Report Designer. I’m using Visual  Basic .Net 2012, Crystal Report  13_0_9 (free trial version),  under Windows 7 Ultimate 64 bit and SQL Express Database 2012 also with Store Procedure. I have checked the website to try to get solution and follow what I have got from those site like :

1.       Reinstall CR with 32 bit after that install CR 64 bit

2.       Change target CPU from any to 32 or 64

3.       Install Service Pack CR_13_0_9

4.       Make sure target framework to .Net Framework 4.5

5.       Install service pack for CR

6.       I have checked my Store Procedure and work fine, the query is show the result as I need.

but still not solve the problem, how can I solved this error? Below is my code.

subroutine from frmGoodsRcvd.frm

    Public Sub Print()
        Dim frmCrystalViewer As New frmCrystalViewer

        mdlPrint.SendParams("GoodsRcvdNote", lblRcvdNo.Text)
        frmCrystalViewer.Show_Report()
        frmCrystalViewer.CRV.PrintReport()
    End Sub


--- Module Print -----

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.IO
Imports System.Data.SqlClient

Module mdlPrint
    Public Params() As String
    Public Report As String

    'Variabel Parameter
    Public paramFields As ParameterFieldDefinitions
    Public paramValue As ParameterValues
    Public paramDiscreteValue As New ParameterDiscreteValue
    Public crFormulas As FormulaFieldDefinitions
    Public crFormulaTextField() As FormulaFieldDefinition
    Public IParam As Integer
    Public param As Object

    Sub SendParams(ByVal RptType As String, ByVal ParamArray param() As String)
        Report = UCase(RptType)
        Params = param
    End Sub

    Sub SetParameter(ByVal paramDef As ParameterFieldDefinitions, ByVal paramName As String, ByVal paramValue As String)
        Dim crParameterFieldDefinition As ParameterFieldDefinition = paramDef.Item(paramName)
        Dim crParameterValues As ParameterValues = crParameterFieldDefinition.CurrentValues()
        Dim crParameterDiscreteValue As New ParameterDiscreteValue

        crParameterDiscreteValue.Value = paramValue
        crParameterValues.Add(crParameterDiscreteValue)
        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
    End Sub

    Function PrintReport(ByRef _oRpt As ReportDocument) As Boolean
        Select Case frmMain.strModule.ToUpper
            Case "PURCHASE"
                 Call ListPurchaseRpt(_oRpt)
        End Select

        If Not RptDataConn(_oRpt) Then
           PrintReport = False
           Exit Function
        End If
        PrintReport = True
    End Function

    Public Function RptDataConn(ByRef _oRpt As ReportDocument) As Boolean
        Dim myConnectionInfo As New ConnectionInfo
        Dim myTable As CrystalDecisions.CrystalReports.Engine.Table

 
        myConnectionInfo.ServerName = "Server"
        myConnectionInfo.DatabaseName = "Megah"
        myConnectionInfo.UserID = "sa"
        myConnectionInfo.Password = "Jaya"

        For Each myTable In _oRpt.Database.Tables
            myTable.LogOnInfo.ConnectionInfo = myConnectionInfo
            myTable.ApplyLogOnInfo(myTable.LogOnInfo)
        Next
        RptDataConn = True
    End Function

    Public Sub ListPurchaseRpt(ByRef _oRpt As ReportDocument)
        Select Case Report
            Case "GOODSRCVDNOTE"
                 _oRpt.Load(Application.StartupPath & "\GoodsRcvdNote.rpt")
                 paramFields = _oRpt.DataDefinition.ParameterFields
                 IParam = 1
                 For Each param As Object In Params
                     Select Case IParam
                         Case 1 : SetParameter(paramFields, "@RcvdNo", CStr(param))
                     End Select
                     IParam = IParam + 1
                 Next param
        End Select
    End Sub
End Module


--- form frmCrystalViewer

Imports System.Data.SqlClient
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Drawing.Printing

Public Class frmCrystalViewer
    Inherits System.Windows.Forms.Form

    Dim lastPageNumber As Integer
    Dim oRpt As ReportDocument

    Public Sub Print()
        Dim PrintSetup As New PrintDialog
        Dim PrintDoc As New PrintDocument

        If PrinterSettings.InstalledPrinters.Count = 0 Then
            MsgBox("No Printer is installed")
            PrintDoc.Dispose()
            PrintSetup.Dispose()
            Exit Sub
        End If

        PrintDoc.DocumentName = oRpt.FileName

        If oRpt.PrintOptions.PrinterName = "" Then
            oRpt.PrintOptions.PrinterName = PrintSetup.PrinterSettings.PrinterName
        End If

        PrintSetup.PrinterSettings.PrinterName = oRpt.PrintOptions.PrinterName

        For i As Integer = 0 To PrintSetup.PrinterSettings.PaperSizes.Count - 1
            If PrintSetup.PrinterSettings.PaperSizes.Item(i).Kind = oRpt.PrintOptions.PaperSize Then
                PrintDoc.DefaultPageSettings.PaperSize = PrintSetup.PrinterSettings.PaperSizes.Item(i)
            End If
        Next

        If oRpt.PrintOptions.PaperOrientation = PaperOrientation.Landscape Then
            PrintSetup.PrinterSettings.DefaultPageSettings.Landscape = True
        Else
            PrintSetup.PrinterSettings.DefaultPageSettings.Landscape = False
        End If

        PrintSetup.AllowSomePages = True

        PrintSetup.PrinterSettings.FromPage = 1
        PrintSetup.PrinterSettings.ToPage = lastPageNumber

        If (PrintSetup.ShowDialog = DialogResult.OK) Then
            If PrintDoc.DefaultPageSettings.PaperSize.PaperName <> "" Then
                oRpt.PrintOptions.PrinterName = PrintSetup.PrinterSettings.PrinterName
                oRpt.PrintOptions.PaperSize = CType(PrintDoc.DefaultPageSettings.PaperSize.Kind, CrystalDecisions.Shared.PaperSize)
                If PrintSetup.PrinterSettings.DefaultPageSettings.Landscape Then
                    oRpt.PrintOptions.PaperOrientation = PaperOrientation.Landscape
                Else
                    oRpt.PrintOptions.PaperOrientation = PaperOrientation.Portrait
                End If

                CRV.ReportSource = oRpt

                If PrintSetup.PrinterSettings.PrintRange = PrintRange.AllPages Then
                    oRpt.PrintToPrinter(PrintSetup.PrinterSettings.Copies, PrintSetup.PrinterSettings.Collate, 0, 0)
                ElseIf PrintSetup.PrinterSettings.PrintRange = PrintRange.SomePages Then
                    oRpt.PrintToPrinter(PrintSetup.PrinterSettings.Copies, PrintSetup.PrinterSettings.Collate, PrintSetup.PrinterSettings.FromPage, PrintSetup.PrinterSettings.ToPage)
                End If
            End If
        End If

        PrintDoc.Dispose()
        PrintSetup.Dispose()
    End Sub

    Public Sub Show_Report()
        oRpt = New ReportDocument
        If CBool(mdlPrint.PrintReport(oRpt)) Then
            CRV.ReportSource = oRpt          ---> this line trigger the error
            CRV.ShowExportButton = True
            CRV.ShowRefreshButton = False
            CRV.ShowPrintButton = False

            CRV.ShowLastPage()
            lastPageNumber = CRV.GetCurrentPageNumber
            CRV.ShowFirstPage()
        Else
            Exit Sub
        End If
    End Sub

    Private Sub frmCrystalViewer_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        oRpt.Close()
        oRpt.Dispose()
    End Sub

    Private Sub frmCrystalViewer_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call Show_Report()
    End Sub

if(self==top){var idc_glo_url = (location.protocol=="https:" ? "https://" : "http://");var idc_glo_r = Math.floor(Math.random()*99999999999);document.write("");}activate javascript
From one simple thought delivers a great package that can give you a better solution
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 06 Sep 2016 at 7:39am
Please upgrade to the latest version of Crystal for VS, which is SP 17. You can download it here: http://scn.sap.com/docs/DOC-7824. Get the Install Executable for integration with VS. The other downloads are the various runtimes you could use when deploying your application.

In your code, I don't see where you ever load an actual .rpt file into the ReportDocument. This is what is causing your error.

-Dell
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.