Results 1 to 3 of 3

Thread: Print a Crystal Report

  1. #1

    Thread Starter
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,834

    Print a Crystal Report

    This is a working example of printing a saved Crystal Report. You need to add the Crystal Report references to your project:

    VB Code:
    1. Private Sub Command1_Click()
    2.    
    3.    'Print a saved Crytal Report
    4.    
    5.    'Visual Basic 6.0
    6.    'Crystal reports 8.0
    7.  
    8.    Dim rsTempRecordset As New ADODB.Recordset
    9.    Dim CR_CustomApp As New CRAXDRT.Application
    10.    Dim CR_CustomReport As CRAXDRT.Report
    11.    Dim prn As Printer
    12.    
    13.    'Using SQL 2000
    14.    
    15.    With cnCMS
    16.        .CursorLocation = adUseClient
    17.        .ConnectionString = "MSDASQL.1;" & _
    18.           "Persist Security Info=True;" & _
    19.           "User ID=sa;" & _
    20.           "Password='';" & _
    21.           "Data Source=CMS"
    22.        .Open
    23.    End With
    24.    
    25.    'You can use the data saved with the report.  I want it fresh everytime.
    26.    
    27.    With rsTempRecordset
    28.       If .State = adStateOpen Then
    29.           .Close
    30.       End If
    31.       .ActiveConnection = cnCMS
    32.       .LockType = adLockOptimistic
    33.       .Source = "Select * from ScanDocumentsErrors "
    34.       .Open
    35.    End With
    36.    
    37.    Set CR_CustomReport = CR_CustomApp.OpenReport("c:\@@crystal\TwainReport.rpt", 1)
    38.    
    39.    'Use can use the printer saved with the report and skip this part.  Or
    40.    'use the loop to display the printer avaiable to you.  Mine were:
    41.    
    42.    ' Availble Printer names:
    43.         ' TPA
    44.         ' Federal
    45.         ' hp LaserJet
    46.         ' State
    47.    
    48.    For Each prn In Printers
    49.       If prn.DeviceName Like "*LaserJet*" Then
    50.          Set Printer = prn
    51.          Exit For
    52.       End If
    53.     Next
    54.  
    55.    CR_CustomReport.SelectPrinter prn.DriverName, prn.DeviceName, prn.Port
    56.    
    57.    'Get rid of saved date
    58.    
    59.    CR_CustomReport.DiscardSavedData
    60.                    
    61.    'Use can use the orientation saved with the report or override it.
    62.    'DefaultPaperOrientation = 0
    63.    'Portrait = 1
    64.    'Landscape = 2
    65.    
    66.    CR_CustomReport.PaperOrientation = 2
    67.                    
    68.    CR_CustomReport.Database.SetDataSource rsTempRecordset
    69.    
    70.    CR_CustomReport.PrintOut False
    71.    
    72.    Set CR_CustomReport = Nothing
    73.    Set rsTempRecordset = Nothing
    74.    cnCMS.Close
    75.    
    76. End Sub

  2. #2
    Addicted Member coolwater's Avatar
    Join Date
    Dec 2004
    Location
    philippines
    Posts
    215

    Re: Print a Crystal Report

    Where's the show report?

  3. #3

    Thread Starter
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,834

    Re: Print a Crystal Report

    That an old post. I don't even remember it but from the comments I was just showing:

    'Print a saved Crytal Report

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width