Re: Dim oRpt As New CrystalReport1() failing

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Helen (anonymous_at_discussions.microsoft.com)
Date: 04/20/04


Date: Tue, 20 Apr 2004 10:41:02 -0700

Thanks, FubarZA. OK, no errors now. As below, had to change some naming conventions, and am using oledb instead of sql.

BUT, the public sub reportprod doesn't seem to be doing much when I test. I had to move
ShowRefreshButton = False
DisplayGroupTree = False
..Zoom(2)
statements to inside the private sub viewer1 load in order to have them respond.

And I'm still being asked for db uid and pwd info when the viewer opens.

So, now, I want my "vendor" parameter to call the report with discrete values (even one for now to prove it works!!!) and not show the crystal report default parameter dialog box. How do I achieve this?
================================================
Imports System.Data
Imports System.Data.OleDb
Imports CrystalDecisions.CrystalReports.Engine

Public Class Form1
    Inherits System.Windows.Forms.Form

        'This call is required by the Windows Form Designer.
        InitializeComponent()
....
    Public Sub ReportProd(ByVal sReportName As String, ByVal iBNIId As Int16)
        Dim pvCollection As New CrystalDecisions.Shared.ParameterValues()
        Dim pdvProdId As New CrystalDecisions.Shared.ParameterDiscreteValue()
        Dim tbCurrent As CrystalDecisions.CrystalReports.Engine.Table
        Dim tliCurrent As CrystalDecisions.Shared.TableLogOnInfo
        Dim PDTTdev As New ReportDocument()

        Try
            PDTTdev.Load(sReportName)
            For Each tbCurrent In PDTTdev.Database.Tables
                tliCurrent = tbCurrent.LogOnInfo
                With tliCurrent.ConnectionInfo
                    .ServerName = tliCurrent.ConnectionInfo.ServerName
                    .UType = tliCurrent.ConnectionInfo.UserID
                    .Password = tliCurrent.ConnectionInfo.Password
                    .DatabaseName = tliCurrent.ConnectionInfo.DatabaseName

                End With
                tbCurrent.ApplyLogOnInfo(tliCurrent)
            Next tbCurrent
            pdvProdId.Value = iBNIId
            pvCollection.Add(pdvProdId)
            PDTTdev.DataDefinition.ParameterFields("?Vendor").ApplyCurrentValues(pvCollection)
            'CrystalReportViewer1.DisplayGroupTree = False
            'crvReportViewer.DisplayGroupTree = False
            'CrystalReportViewer1.ReportSource = PDTTdev
            'CrystalReportViewer1.Zoom(200)
        Catch Exp As LoadSaveReportException
            MsgBox("Incorrect path for loading report.", MsgBoxStyle.Critical, "Load Report Error")
        Catch Exp As Exception
            MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error")
        End Try
    End Sub
    ' End With

    Private Sub CrystalReportViewer1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CrystalReportViewer1.Load
        Me.CrystalReportViewer1.ShowRefreshButton = False
        Me.CrystalReportViewer1.DisplayGroupTree = False
        Me.CrystalReportViewer1.Zoom(2)
    End Sub

End Class
=================================
     
     ----- FubarZA wrote: -----
     
     Try using it with this method, it worked for me all the time. Change your
     parameters accordingly.
     
     Imports System.Data
     
     Imports System.Data.SqlClient
     
     Imports CrystalDecisions.CrystalReports.Engine
     
     
     
     Public Sub ReportProd(ByVal sReportName As String, ByVal iBNIId As Int16)
     
     Dim pvCollection As New CrystalDecisions.Shared.ParameterValues
     
     Dim pdvProdId As New CrystalDecisions.Shared.ParameterDiscreteValue
     
     Dim tbCurrent As CrystalDecisions.CrystalReports.Engine.Table
     
     Dim tliCurrent As CrystalDecisions.Shared.TableLogOnInfo
     
     Dim rptCustomersOrders As New ReportDocument
     
     Try
     
     rptCustomersOrders.Load(sReportName)
     
     For Each tbCurrent In rptCustomersOrders.Database.Tables
     
     tliCurrent = tbCurrent.LogOnInfo
     
     With tliCurrent.ConnectionInfo
     
     ..ServerName = cnProperties.sServerName
     
     ..UserID = cnProperties.sUserId
     
     ..Password = cnProperties.sPassword
     
     ..DatabaseName = cnProperties.sDatabaseName
     
     End With
     
     tbCurrent.ApplyLogOnInfo(tliCurrent)
     
     Next tbCurrent
     
     pdvProdId.Value = iBNIId
     
     pvCollection.Add(pdvProdId)
     
     rptCustomersOrders.DataDefinition.ParameterFields("@BNIId").ApplyCurrentValu
     es(pvCollection)
     
     crvReportViewer.DisplayGroupTree = False
     
     crvReportViewer.ReportSource = rptCustomersOrders
     
     crvReportViewer.Zoom(2)
     
     Catch Exp As LoadSaveReportException
     
     MsgBox("Incorrect path for loading report.", _
     
     MsgBoxStyle.Critical, "Load Report Error")
     
     Catch Exp As Exception
     
     MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error")
     
     End Try
     
     End Sub
     
     
     "Helen" <anonymous@discussions.microsoft.com> wrote in message
     news:5F0D2D6F-4E0C-46B6-AEEE-BE716FBCEBF4@microsoft.com...
> Trying to post this (3rd attempt) ...
>> Thanks, Bernie, for working with me on this issue. Please HELP! I'm
     running up against a deadline (of course!)
>> I've created a new win form with a crystal viewer and a report doc control
     and a strongly typed rpt called pdttdev, vendor is the parameter name.
>> Tested with and without imports statements at top, error messages differed
     in each case. So, here goes with the imports statements.
>> Tried your example, but the naming extensions are still giving errors,
     tested and replaced as shown below. Do you see any issues with these? Now,
     just error messages on:
> mglobals.gl_bipvar()
> mglobals.gl_issuecode
> mglobals.gl_tname
> mglobals.gl_qty1
> mglobals.gl_coverprice
>> Getting "...is not a member of CrystalDecisions.Shared.ParameterFields" in
     all cases (gl_bipvar, gl_issuecode, gl_tname, gl_qty1, gl_coverprice)
>> =========================
> Imports CrystalDecisions.CrystalReports.Engine
> Imports CrystalDecisions.Shared
>> Public Class Form1
> Inherits System.Windows.Forms.Form
>> Dim paramField As New ParameterField()
> Dim paramField2 As New ParameterField()
> Dim paramField3 As New ParameterField()
> Dim paramField4 As New ParameterField()
> Dim paramField5 As New ParameterField()
>> Dim discreteVal As New ValueOptions()
> Dim discreteVal2 As New ValueOptions()
> Dim discreteVal3 As New ValueOptions()
> Dim discreteVal4 As New ValueOptions()
> Dim discreteVal5 As New ValueOptions()
>>> Dim paramFields As New ParameterFields()
> Dim paramFields2 As New ParameterFields()
> Dim paramFields3 As New ParameterFields()
> Dim paramFields4 As New ParameterFields()
> Dim paramFields5 As New ParameterFields()
>> Dim parameterdiscreteval As New
     CrystalDecisions.Shared.ParameterDiscreteValue()
> Dim parameterdiscreteval2 As New
     CrystalDecisions.Shared.ParameterDiscreteValue()
> Dim parameterdiscreteval3 As New
     CrystalDecisions.Shared.ParameterDiscreteValue()
> Dim parameterdiscreteval4 As New
     CrystalDecisions.Shared.ParameterDiscreteValue()
> Dim parameterdiscreteval5 As New
     CrystalDecisions.Shared.ParameterDiscreteValue()
>> Dim mglobals As New ParameterFields()
>> 'Dim mglobals As New Globalization(global)
>> #Region " Windows Form Designer generated code "
>> Public Sub New()
> MyBase.New()
>> 'This call is required by the Windows Form Designer.
> InitializeComponent()
>> 'Add any initialization after the InitializeComponent() call
>> Select Case "C:/Program Files/Visual Studio .NET/Crystal
     Reports/PDTTdev.rpt" 'this is 'glbrowseprintvar', which will be the
     reportsource property
>> End Select
>> Me.CrystalReportViewer1.ShowRefreshButton = False
> paramField.ParameterFieldName = "Vendor"
> paramField2.ParameterFieldName = "pissuecodes"
> paramField3.ParameterFieldName = "pretailers"
> paramField4.ParameterFieldName = "pcounter"
> paramField5.ParameterFieldName = "peffper"
>> 'above are the actual parameter names inside the report
>> 'testing below to try, parameterdiscreteval.Value etc not causing
     errors now
> parameterdiscreteval.Value = mglobals.gl_bipvar()
> parameterdiscreteval2.Value = mglobals.gl_issuecode
> parameterdiscreteval3.Value = mglobals.gl_tname
> parameterdiscreteval4.Value = mglobals.gl_qty1
> parameterdiscreteval5.Value = mglobals.gl_coverprice
>> 'in place of
> 'discreteVal.Val.


Quantcast