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.