views:

45

answers:

1

Hello - I've been trying to build a simple vb.net app that basically displays already built .rpt reports in a crystalreportviewer. No matter how many times I try to code it, I run into problems. Some reports have worked, others have thrown errors such as load report failed, invalid path, etc.. All of the reports work when I run them in crystal.

Ideally, I'm looking to just have a menu with report names, and a crystalreportviewer where the user can click a report, and the app prompts them for parameter values.

I'm currently working with crystal 9 I believe, and vs.net 2003, or I have access to 2005 as well.

Can someone help me with this, or explain why I'm running into problems? Nothing has been consistent - I'm at a loss right now.

Help is highly appreciated!! thanks in advance

A: 

You need to get them all working in the development environment, then on the client side, make sure the dependent files are installed and the network drive names are mapped consistently if your code's dependent on it.

Here's an example in VB.NET 2005:

Public Class frmCrystal
    Public Sub _init(ByVal windowTitle As String, ByVal rptPath As String)
        Dim rptDoc As CrystalDecisions.CrystalReports.Engine.ReportDocument
        Dim ConInfo As CrystalDecisions.Shared.TableLogOnInfo
        Dim crTables As CrystalDecisions.CrystalReports.Engine.Tables
        Dim crTable As CrystalDecisions.CrystalReports.Engine.Table

        Me.Text = windowTitle
        rptDoc = New CrystalDecisions.CrystalReports.Engine.ReportDocument
        rptDoc.Load(rptPath)
        ConInfo = New CrystalDecisions.Shared.TableLogOnInfo
        crTables = rptDoc.Database.Tables
        For Each crTable In crTables
            With ConInfo.ConnectionInfo
                .ServerName = "dhsdev10069\dsd"
                .DatabaseName = "DSDWorkPlanTracking"
                .IntegratedSecurity = True
            End With
            ConInfo.ReportName = rptPath
            crTable.ApplyLogOnInfo(ConInfo)
        Next

        rptCrystal.ReportSource = rptDoc
    End Sub

the form frmCrystal contains one CrystalReportViewer control:

Private Sub InitializeComponent()
        Me.rptCrystal = New CrystalDecisions.Windows.Forms.CrystalReportViewer
        Me.SuspendLayout()
        '
        'rptCrystal
        '
        Me.rptCrystal.ActiveViewIndex = -1
        Me.rptCrystal.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.rptCrystal.DisplayGroupTree = False
        Me.rptCrystal.Dock = System.Windows.Forms.DockStyle.Fill
        Me.rptCrystal.Location = New System.Drawing.Point(0, 0)
        Me.rptCrystal.Name = "rptCrystal"
        Me.rptCrystal.Size = New System.Drawing.Size(292, 273)
        Me.rptCrystal.TabIndex = 0
        '
        'frmCrystal
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(292, 273)
        Me.Controls.Add(Me.rptCrystal)
        Me.Name = "frmCrystal"
        Me.Text = "DSD Report"
        Me.ResumeLayout(False)

    End Sub
End Class

Then to call the form, you need something like:

Private _crystal As frmCrystal

    _crystal = New frmCrystal
    _crystal.MdiParent = Me
    _crystal._init(windowTitle, rptpath)
    _crystal.WindowState = FormWindowState.Maximized
    _crystal.Show()
Beth
Unfortunately I haven't been able to get the reports working in the development environment. I was hoping someone could provide me with basic working code for this that I can give a shot.
JBOMB
which version of VB.NET? I can post for 2005
Beth
Sure 2005 works, thanks Beth!!
JBOMB
Hi Beth, I took this code and put it into a new form in vs 2005, added a CrytalReportViewer control and renamed it to rptCrystal - it compiled ok but when I run it it doesn't do anything. Am I missing something? Thanks again for the help
JBOMB
yes, you need to call it with your report path. pls. see edit.
Beth
Hi Beth, thanks again for the help. This may sound stupid but I still don't get it. I copied that new code in and it says _crystal is not declared.
JBOMB
Ok hang on a sec, I might have gotten something working :) I'll let you know if I run into any problems or questions. Thanks a million for the help so far! :)
JBOMB