hi to all

I have list of names in list view with corresponding unique employee id. The user could select more rows. In each employee id I will find it in database in retrieve all the details information and print it using crystal report. What I want is in each employee id it will print in separate pages.

Currently using my code, the records of other employee id will append on the current page instead to print in another page with new header and footer.

Any help would greatly appreciated

Thanks in advance

Please see this link of my crystal report designer http://www.shopgruppo.com/dchallenger/crystal-report.jpg

Below code is my form with crystalreportviewer

Private Sub frmIndividualDTRPrint_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim frmRefIndividualDTR As frmIndividualDTR = DirectCast(frmMain.ActiveMdiChild, frmIndividualDTR)
    Dim dtFromDate As DateTime = frmRefIndividualDTR.dtpFromDate.Text
    Dim dtToDate As DateTime = frmRefIndividualDTR.dtpToDate.Text

    Dim myRpt As New IndividualDTRReport

    Dim txtHeader As CrystalDecisions.CrystalReports.Engine.TextObject = myRpt.Section2.ReportObjects("txtHeader")
    txtHeader.Text = "No Bia Inc. Timecard Report"

    Dim txtDateNow As CrystalDecisions.CrystalReports.Engine.TextObject = myRpt.Section2.ReportObjects("txtDateNow")
    txtDateNow.Text = "Period Covered " & Format(dtFromDate, "d MMMM yyyy") & " - " & Format(dtToDate, "d MMMM yyyy")

    Dim row As DataRow = Nothing
    Dim DS As New DataSet

    'ADD A TABLE TO THE DATASET
    DS.Tables.Add("individual_dtr")

    'ADD THE COLUMNS TO THE TABLE
    With DS.Tables(0).Columns
      .Add("employee_id", Type.GetType("System.String"))
      .Add("name", Type.GetType("System.String"))
      .Add("position", Type.GetType("System.String"))
      .Add("date", Type.GetType("System.String"))
      .Add("shift_schedule", Type.GetType("System.String"))
      .Add("time_in", Type.GetType("System.String"))
      .Add("break_in", Type.GetType("System.String"))
      .Add("break_out", Type.GetType("System.String"))
      .Add("time_out", Type.GetType("System.String"))<br/>      .Add("total_work", Type.GetType("System.String"))<br/>     End With

    Dim sSQL As String
    Dim i As Integer

    'LOOP THE LISTVIEW AND ADD A ROW TO THE TABLE FOR EACH LISTVIEWITEM
    For i = 0 To frmRefIndividualDTR.lsvIndividualDTR.SelectedItems.Count - 1

      Dim current As DateTime = dtFromDate

      While current <= dtToDate
        sSQL = "SELECT * FROM ((((pr_employees LEFT OUTER JOIN"
        sSQL += " pr_employees_other_info ON pr_employees.employee_id = pr_employees_other_info.employee_id)"
        sSQL += " LEFT OUTER JOIN pr_department ON pr_employees_other_info.department_id = pr_department.department_id)"
        sSQL += " INNER JOIN (SELECT * FROM pr_timecard WHERE (current_date_transaction = #" & Format(current, "yyyy/MM/dd") & "# AND employee_id = " & frmRefIndividualDTR.lsvIndividualDTR.SelectedItems(i).Text & ")) AS Q1 ON (pr_employees.employee_id = Q1.employee_id))"
        sSQL += " LEFT OUTER JOIN pr_shift_scheduled ON pr_employees.shift_id = pr_shift_scheduled.shift_id)"
        sSQL += " LEFT OUTER JOIN pr_timecard_break ON Q1.current_date_transaction = pr_timecard_break.current_date_transaction"
        ReadSQL(sSQL)

        If reader.HasRows Then
          reader.Read()

          row = DS.Tables(0).NewRow

          row(0) = RVI(reader("pr_employees.employee_id"))
          row(1) = RVS(reader("last_name")) & ", " & RVS(reader("middle_name")) & ", " & RVS(reader("first_name"))
          row(2) = RVS(reader("position_desired")) & " / " & RVS(reader("department_type"))
          row(3) = RVS(reader("current_transaction"))
          row(4) = RVS(reader("start_time")).Substring(0, 5) & "-" & RVS(reader("end_time")).Substring(0, 5)
          row(5) = RVS(reader("time_in"))
          row(6) = RVS(reader("break_in"))
          row(7) = RVS(reader("break_out"))
          row(8) = RVS(reader("time_out"))<br/>          row(9) = RVS(reader("total_work"))<br/>           DS.Tables(0).Rows.Add(row)
        Else
          row = DS.Tables(0).NewRow

          row(3) = Format(current, "d MMMM-ddd")
          row(4) = ""
          row(5) = ""
          row(6) = ""
          row(7) = ""
          row(8) = ""<br/>           row(9) = "" <br/>          DS.Tables(0).Rows.Add(row)
        End If
        current = current.AddDays(1)
      End While
    Next

    myRpt.SetDataSource(DS)
    CrystalReportViewer1.ReportSource = myRpt
    CrystalReportViewer1.Refresh()

    'DISPOSE OF THE DATASET
    DS.Dispose()
    DS = Nothing
  End Sub

hi..

right click on your Detail Section's Header. then select the Selection Expert from dropdown.

now check : New Page After

its done.
see screen shot for more info

hi sandeepparekh9,

Thanks for your immediate replied.

I tried your instruction but in every record of one employee id will go in each page instead of all records of one employee id at the same pages.

Kindly take a look at the screen shot below.

Thanks

hi sandeepparekh9,

Thanks for your best solution. It works perfectly. Your the great...

Best Regards
Tirso

hi..
i am glad to help..

:)

ps: please mark the thread as solved. :)

I am trying to print each group on new page. Its working fine but it keep first page blank with only header part then starts printing each group on new with headers.
Pl. help me

hi sandeepparekh9,
Thanks alot, Your solution works for me too.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.