• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 346
  • Last Modified:

printing crystal report records

how can I print a record from a crystal report.
0
MrBlubke
Asked:
MrBlubke
1 Solution
 
MrBlubkeAuthor Commented:
please rather urgent....
0
 
Éric MoreauSenior .Net ConsultantCommented:
This is a procedure that will help you print CR report from VB.

You can specify a criteria. This will reduce the amount of data printed.

Public Sub PrintCRReport(ByVal pstrReportFile As String, _
                          Optional ByVal pstrCriteria As Variant, _
                          Optional ByVal pbytDestination As Byte = 0)
Dim intResult As Integer

    With fMainForm.CrystalReport1
        If Not IsMissing(pstrCriteria) Then
            .SelectionFormula = pstrCriteria
        End If

        .WindowState = crptMaximized
         
        .ReportFileName = App.path & "\" & pstrReportFile
        .Destination = pbytDestination
        .WindowTitle = App.Title & " - " & pstrReportFile
         
        intResult = .PrintReport
        If intResult <> 0 Then
            MsgBox "Error occured." & _
                   vbCrLf & .LastErrorNumber & ": " & .LastErrorString, _
                   vbCritical + vbOKOnly, _
                   "Print error"
        End If
    End With
End Sub
0
 
ChaseZeroCommented:
to call the actual file (eg Report.rpt) that was generated in VB all u have to do is

CrystalReport1.ReportFileName = "c:\report\filename.rpt"

so u can change that for different reports.... obviously the report must be configured to read the correct database and layout must be designed first.

to run the report in a preview window see the example code below having first putting the crystal report control on that form, and renaming it to CrystalReport

   Dim result As Integer
   
   CrystalReport.ReportFileName = c:\Reports\PatientWeekly.rpt"
' here would be crptToPrinter if u wanted to print it
   CrystalReport.Destination = crptToWindow
   result = CrystalReport.PrintReport
   
   If result <> 0 Then
      MsgBox "Print Error, Error Number = " & result
   End If

at the end if there is an error the user would be notified...

This is a simple code off the top of my head, it can be more complicated than that with more errorhandling routines
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

Tackle projects and never again get stuck behind a technical roadblock.
Join Now