Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: running multiple reports Post Reply Post New Topic
Author Message
carlp22
Newbie
Newbie


Joined: 21 May 2007
Location: United States
Online Status: Offline
Posts: 5
Quote carlp22 Replybullet Topic: running multiple reports
    Posted: 20 Jul 2007 at 3:52pm
Hello All,

I’m using Visual Studio 2005, (VB) with a Windows form with a CrystalReportsViewer (XI).

 

 

I am trying to select data, run the report for that data, then repeat that process.

 

Example;

 I might need to select codes “A” and “B” from a database table. 

 

1)      Select all code “A” records.

2)      Run a report using the Report_A report.

3)      Select all code “B” records.

4)   Run a report using the Report_B report.

 

My problem is – the code "B" report is displayed and contains codes "A" and "B"!

 

Please help.

 

 

 

sCode = orLetterGroups("FulFillCode").ToString.Trim

 

Dim strReportName As String = “Report_A"

 

Dim strReportPath As String = "C:\Reports\" & strReportName & ".rpt"

 

Dim myReportDocument As ReportDocument = New ReportDocument()

myReportDocument.Load(strReportPath)

CrystalReportViewer1.ReportSource = myReportDocument

 

myReportDocument.SetDataSource(myDataTable)

 

IP IP Logged
jkwrpc
Senior Member
Senior Member


Joined: 19 Jun 2007
Location: United States
Online Status: Offline
Posts: 432
Quote jkwrpc Replybullet Posted: 21 Jul 2007 at 7:56am
I am not seeing in the code where you pass the fulfill code (I assume this the Letter Codes such as A or B) to your data source.
 
Regardless, make sure your variables are being properly reset, look at your record selection statement. If you only have two letter codes and A & B represents all your records then again it will point towards a problem with the variable not getting properly passed or reset.
 
 
Regards,
 
John W.
 
IP IP Logged
carlp22
Newbie
Newbie


Joined: 21 May 2007
Location: United States
Online Status: Offline
Posts: 5
Quote carlp22 Replybullet Posted: 21 Jul 2007 at 9:27am
Thanks for the reply John.
 
I was trying to simplify the example and it's more like pseudo code.  The variables are correct and I'm clearing everything. 
 
How would I print directly to the printer instead of using the CrystalReportViewer?  This might solve the problem.
 
Thanks,
Carl
 
IP IP Logged
jkwrpc
Senior Member
Senior Member


Joined: 19 Jun 2007
Location: United States
Online Status: Offline
Posts: 432
Quote jkwrpc Replybullet Posted: 21 Jul 2007 at 12:11pm
Actually I find the CR Viewer quite useful. It gives the end users quite a bit of control. I use it nearly 100% of the time. I truly doubt the issue you are having is with the Viewer.  I move any numbers of parameters through it without it causing the errors. I still make enougn on my own.
 
To bypass the Viewer I believe your will have to code against Report object and probably the Report Engine.  You can control the output destination through their object members.
 
Just curious, where is the data query being run? I ask because you have the datasource set to a datatable but I dont see any code for it. If you could pass along the code in the form holding the report viewer used to create the data,  it might give the forum members a better shot at helping you. That is assuming the code is a few lines.
 
Regards,
 
John W.
IP IP Logged
carlp22
Newbie
Newbie


Joined: 21 May 2007
Location: United States
Online Status: Offline
Posts: 5
Quote carlp22 Replybullet Posted: 21 Jul 2007 at 12:46pm
Thanks again John.  I would like to ues the CrystalReportViewer, but I don't think I can send multiple reports to it. 
 
Here's the simplified code. Again, it will generate a report for each code selected (A, B, C, and so on).  The SQLs work fine, it's just that the only report I see is the last one generated and it has all the codes in it (not just the code it should have).
 
Thanks,
Carl
 
 
 

Sub PrintAllReportsForAllCodes()

Dim sSql As String = ""

Dim sCode As String = ""

sSql = "SELECT Unique Codes ("A", "B", "C",...")

Dim cmd As OracleCommand = New OracleCommand(sSql)

cmd.Connection = ConOra

cmd.CommandType = CommandType.Text

Dim orLetterGroups As OracleDataReader = cmd.ExecuteReader()

While orLetterGroups.Read

' get the report for this Code

sCode = orLetterGroups("Code").ToString.Trim

Dim strReportName As String = orLetterGroups("ReportName")

Dim strReportPath As String = "C:\Reports\" & strReportName & ".rpt"

sSql = "SELECT Name, Address,... WHERE Code = '" & sCode & "') "

Dim rdLetters As OracleDataReader = ReturnDataReader(sSql)

Dim cmd2 As OracleCommand = New OracleCommand(sSql)

cmd2.Connection = ConOra

cmd2.CommandType = CommandType.Text

Dim myreader As OracleDataReader = cmd2.ExecuteReader()

Dim myDataTable As New DataTable

If myreader.HasRows Then

myDataTable.Load(myreader)

myreader.Close()

End If

Dim myReportDocument As ReportDocument = New ReportDocument()

myReportDocument.Load(strReportPath)

CrystalReportViewer1.ReportSource = myReportDocument

myReportDocument.SetDataSource(myDataTable)

CrystalReportViewer1.ShowGroupTreeButton = True

CrystalReportViewer1.ShowExportButton = True

End While

End Sub

IP IP Logged
jkwrpc
Senior Member
Senior Member


Joined: 19 Jun 2007
Location: United States
Online Status: Offline
Posts: 432
Quote jkwrpc Replybullet Posted: 22 Jul 2007 at 1:25pm
I may have a suggestion to fix your problem.
 
It seems that you load data into the data table on each cycle of the report. Assume you run code A  then run the report  then run the report code B.
 
Keep in mind everything is happening in the WHILE structure. The first time you load the table it is filled with rows related to A then when you run with code B the datatable still holds code A data and is now loaded with those rows related to Code B. The table is now holding A & B rows.  So your first report is A and the second report is A & B, the next would likely be A,B, & C. 
 
Yoiu may need to flush the data from the objects holding the data such as the data table from the previous run. Probably several ways to do this. I see you reinitialize the datatable each time  in the WHILE loop which you think would deal with the problem, but it might be worth destroying the object before you recreate to see what happens.  
 
Clear as mud I suppose...
 
Hope it helps or at least will help get you to a correct solution.
 
John W.
 
John W.
Regards,

John W.
www.CustomReportWriters.net
IP IP Logged
carlp22
Newbie
Newbie


Joined: 21 May 2007
Location: United States
Online Status: Offline
Posts: 5
Quote carlp22 Replybullet Posted: 22 Jul 2007 at 3:28pm
Thanks again for the reply John,
 
I did clear the data table in previous attempts with the same result, but did not destroy it.  I'll try that.
 
In the meantime, I'm printing directly to the printer and all is fine.
 
Thanks,
Carl
 
IP IP Logged
jkwrpc
Senior Member
Senior Member


Joined: 19 Jun 2007
Location: United States
Online Status: Offline
Posts: 432
Quote jkwrpc Replybullet Posted: 24 Jul 2007 at 11:22am
Carl:

I made a quick MS Access db holding a couple of fields, one of which is a letter code for A, B, C etc and then made a simple report. I attached everything to a viewer and worked with the code.
 
I am out of time but I did get the report to work using the viewer. It has one problem remaining but I am out of time for this... so I will leave it to you to pursue if you have an interest. It does display and print the 'A's then the B's and so forth.
 
While I am using an Access db and an OLEDB connection and command objects; here is is my code, which still relied heavily on yours using datareaders etc.
 
------------------------------------------------------

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Show()
        PrintAllReportsForAllCodes()
    End Sub
    Sub PrintAllReportsForAllCodes()
        Try
            Dim sCode As String
            Dim sSql As String = "SELECT Distinct LetterCode from ltrcode"
            Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\jwillems\Desktop\atod.mdb;")
            Dim cmd As New OleDb.OleDbCommand
            conn.Open()
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = sSql
            Dim orLetterGroups As OleDb.OleDbDataReader = cmd.ExecuteReader()
            Dim intCounter As Integer
            While orLetterGroups.Read()
                sCode = orLetterGroups("LetterCode")
                For Each sCode In orLetterGroups("LetterCode")
                    Dim rpt As New CrystalReport1
                    rpt.Load()
                    Dim cmd2 As New OleDb.OleDbCommand(sSql)
                    sSql = "SELECT id,lettercode FROM ltrCode WHERE LetterCode = '" & sCode & "' "
                    intCounter = intCounter + 1
                    CrystalReportViewer1.ReportSource = rpt
                    CrystalReportViewer1.SelectionFormula = "{ltrcode.lettercode}= '" & sCode & "';"
                    CrystalReportViewer1.PrintReport()
                Next
            End While
            conn.Close()
        Catch ex As Exception
            Dim strMsg As String = ex.Message
        End Try
    End Sub

-------------------------------------------------------

I used a simple winform, added a viewer, then put this code in the winform codebehind page. I use the CR selection formula for the data rather than a datatable. It was just easier for me to create. You may have reasons to keep using the datatable.

The remaining issue seems to be getting the viewer to pause at the end of the FOR EACH  statement but before the NEXTcommand. Right now I use the PrintReport property but it is not the correct solution. It does not allow the user full use of the CR Viewer functions. There must be a better way to pause the process. Again, time keeps me from searching further but I thought I would pass this much on.
 
Let me know if you carry this out to a full solution.
 
Regards,
 
John W.

 


 

 
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.063 seconds.