Need to know basics of printing a Cyrstal Report

Hi

I am using VB.Net 2005 and have created a crystal report successfully using the wizard. It is called standsummary.rpt.

I have no idea on how to proceed. What do I do to get this sucker to print? Please provide the basics. I have been teaching myself how to do the reports for hours now and have sucessfully created my first xml from a dataset. The Crystal Report is based on the XML. Where do I go next?

Here is my code in Form2 used to create the xml. No problems there. I just don't know how to tie the report printing process into this.

   'build report dataset
        Dim dt As New DataTable("StandInfo")
        dt.Columns.Add("StandNum")
        dt.Columns.Add("Area")
        dt.Columns.Add("SampleSize")
        dt.Columns.Add("TotalPoints")
        dt.Columns.Add("Intensity")

        Dim row As DataRow = dt.NewRow()
        Dim item As ListViewItem
        For Each item In lvStands.Items
            row("StandNum") = item.Text
            row("Area") = item.SubItems(1).Text
            row("SampleSize") = item.SubItems(2).Text
            row("TotalPoints") = item.SubItems(3).Text
            row("Intensity") = item.SubItems(4).Text
            dt.Rows.Add(row)
            row = dt.NewRow()
        Next

        Dim SourceDir As String = lblRPath.Text
        Dim source As DirectoryInfo = New DirectoryInfo(SourceDir)

        If Not source.Exists Then
            source.Create()
        End If

        Dim fi As FileInfo

        For Each fi In source.GetFiles("*.xml")
            If fi.Name = "standsummary.xml" Then
                fi.Delete()
            End If
        Next

        dt.WriteXml(SourceDir & "\" & "standsummary.xml")

        MsgBox("table build complete")
PBLackAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PBLackAuthor Commented:
Hi

I am having a problem with:

mrptDoc.Load(Forms.Application.StartupPath & "\rptTest.rpt")

I get an error that name Forms is not declared. So how do I fix that? Also I want all reports to reside in the folder Application.StartupPath & "\Reports". How do I programatically place the report there?

Thanks for the help
0
PBLackAuthor Commented:
FYI here is my code. I changed the line:

mrptDoc.Load(Forms.Application.StartupPath & "\standsummary.rpt") to

mrptDoc.Load(Application.StartupPath & "\standsummary.rpt") and it throws the following error:

Load report failed.

All of this code is in the Load event of Form9 which contains CrystalReportViewer1

        'build report dataset
        Dim dt As New DataTable("StandInfo")
        dt.Columns.Add("StandNum")
        dt.Columns.Add("Area")
        dt.Columns.Add("SampleSize")
        dt.Columns.Add("TotalPoints")
        dt.Columns.Add("Intensity")

        Dim row As DataRow = dt.NewRow()
        Dim item As ListViewItem
        For Each item In Form2.lvStands.Items
            row("StandNum") = item.Text
            row("Area") = item.SubItems(1).Text
            row("SampleSize") = item.SubItems(2).Text
            row("TotalPoints") = item.SubItems(3).Text
            row("Intensity") = item.SubItems(4).Text
            dt.Rows.Add(row)
            row = dt.NewRow()
        Next

        Dim SourceDir As String = "c:\Temp"
        Dim source As DirectoryInfo = New DirectoryInfo(SourceDir)

        If Not source.Exists Then
            source.Create()
        End If

        Dim fi As FileInfo

        For Each fi In source.GetFiles("*.xsd")
            If fi.Name = "standsummary.xsd" Then
                fi.Delete()
            End If
        Next

        dt.WriteXmlSchema("c:\Temp\standsummary.xsd")
        'Load the standalone report
        mrptDoc.Load(Application.StartupPath & "\standsummary.rpt")
        'Pass the dataset to the report
        mrptDoc.SetDataSource(dt)
        'Pass the Report Document object to the viewer
        CrystalReportViewer1.ReportSource = mrptDoc
0
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

Éric MoreauSenior .Net ConsultantCommented:
>>mrptDoc.Load(Application.StartupPath & "\standsummary.rpt") and it throws the following error:
>>Load report failed.

if you do a:
messagebox.show(Application.StartupPath & "\standsummary.rpt")
it will give you the full path where the report should be. Is it there?

>>Also I want all reports to reside in the folder Application.StartupPath & "\Reports". How do I programatically place the report there?

Unless you have the designer to save directly to that folder (and I don't like this idea because if you have many reports, they are all in that same folder), there is no way. I have created a solution just to edit my reports. This solution saves the reports in a hierarchy of folders. I also have a batch file that copies from that hierarchy of folders to my single folder where the application is reading the reports from. When I modify a report, I run this batch file.
0
Éric MoreauSenior .Net ConsultantCommented:
>>dt.WriteXmlSchema("c:\Temp\standsummary.xsd")

You don't have to do it every time you print a report!
0
PBLackAuthor Commented:
Hi again

I am sorry to be a pain in the butt. I am completely lost. I did get the report to open but it is void of data. I discovered that I had not set the build action to none...but now I have a host of other problems.

Can you please look everything over an point out to me where I went wrong. I know it is all newbie mistakes but I am trying hard to get a handle on this.

On form2 behind a print button I have:

   Dim frm As Form
        For Each frm In Me.MdiParent.MdiChildren
            If TypeOf frm Is Form9 Then
                frm.Close()
            End If
        Next

        'build report dataset
        Dim dt As New DataTable("StandInfo")
        dt.Columns.Add("StandNum")
        dt.Columns.Add("Area")
        dt.Columns.Add("SampleSize")
        dt.Columns.Add("TotalPoints")
        dt.Columns.Add("Intensity")

        Dim row As DataRow = dt.NewRow()
        Dim item As ListViewItem

        For Each item In lvStands.Items
            row("StandNum") = item.Text
            row("Area") = item.SubItems(1).Text
            row("SampleSize") = item.SubItems(2).Text
            row("TotalPoints") = item.SubItems(3).Text
            row("Intensity") = item.SubItems(4).Text
            dt.Rows.Add(row)
            row = dt.NewRow()
        Next

        Dim SourceDir As String = "c:\Temp"
        Dim source As DirectoryInfo = New DirectoryInfo(SourceDir)

        If Not source.Exists Then
            source.Create()
        End If

        Dim fi As FileInfo

        For Each fi In source.GetFiles("*.xsd")
            If fi.Name = "standsummary.xsd" Then
                fi.Delete()
            End If
        Next

        dt.WriteXmlSchema("c:\Temp\standsummary.xsd")

Leave code for a side note:
+++++++++ I know you said not to do this but I do not think that this is the problem. From what I can gather this just makes an empty shell for the data to be stored in but does not actually house the data. So if I am correct is my above code for populating it not working?
How do I fix that part?++++++++++++

Back to code behind button:

        Dim F As New Form9
        F.MdiParent = Main
        F.Show()

On form 9 I have in the load event the following:

        'Load the standalone report

        mrptDoc.Load(Application.StartupPath & "\standsummary.rpt")
        'Pass the dataset to the report
        mrptDoc.SetDataSource("c:\Temp\standsummary.xsd")
        'Pass the Report Document object to the viewer
        CrystalReportViewer1.ReportSource = mrptDoc

This form also has CrystalReportView1 added and

Imports System.Data.DataSet
Imports CrystalDecisions.CrystalReports.Engine
Public Class Form9
Private mrptDoc As New ReportDocument

So Eric if you would be so kind has to show me where I have gone wrong I would really appreciate it.

Thanks

PBlack
0
Éric MoreauSenior .Net ConsultantCommented:
>>mrptDoc.SetDataSource("c:\Temp\standsummary.xsd")

a .xsd file is a schema. it doesn't contain data.

Go through the example in my article. It will work.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.