J'utilise CR 8.5
Dans un form j'ai l'activeX CRViewer.
J'utilise la fonction suivante pour afficher différents états dans le formulaire:
Public Sub PrintFrm(ByVal ReportFile As String, WindowTitle As String, Optional RecordSelector As String, Optional PrintReport As Boolean = False, Optional ReportHeader As Boolean = False, Optional ExportEnable As Boolean = False, Optional ReportLandscape As Boolean = False)
On Error GoTo Err_Print
Dim crystal As New CRAXDDRT.Application
Dim Report As New CRAXDDRT.Report
Dim MyRsSubRep As New ADODB.Recordset
Dim StrSql As String
Set Report = crystal.OpenReport(App.Path & "\Report\" & ReportFile & ".rpt")
If ReportHeader Then Report.ReportTitle = WindowTitle
'Sélection de l'imprimante
If ReportFile = "Ticket" Then
Report.SelectPrinter Printers(PrinterTicket).DriverName, Printers(PrinterTicket).DeviceName, Printers(PrinterTicket).Port
Else
Report.SelectPrinter Printers(PrinterA4).DriverName, Printers(PrinterA4).DeviceName, Printers(PrinterA4).Port
End If
If ReportLandscape Then Report.PaperOrientation = crLandscape
If RecordSelector <> "" Then Report.RecordSelectionFormula = RecordSelector
If PrintReport Then
Report.ReadRecords 'Refresh
Report.PrintOut False
Else
'FrmPrint.Show vbModal
With FrmPrint.CRViewer1
.ReportSource = Report
.ViewReport 'SHOW REPORT
Do While .IsBusy 'ZOOM METHOD DOES NOT WORK WHILE
DoEvents 'REPORT IS LOADING, SO WE MUST PAUSE
Loop 'WHILE REPORT LOADS.
'Modification affichage
.Refresh
.Zoom 1
.Top = 0
.Left = 0
.Height = FrmPrint.ScaleHeight
.Width = FrmPrint.ScaleWidth
.DisplayTabs = False
.DisplayGroupTree = False
.EnableExportButton = ExportEnable
.EnableGroupTree = False
.DisplayBackgroundEdge = False
'.EnableSearchControl = False
.EnableNavigationControls = True
End With
With FrmPrint
.Caption = WindowTitle
.Show vbModal
.Refresh
End With
End If
Set crystal = Nothing
Set Report = Nothing
Exit Sub
Err_Print:
Set crystal = Nothing
Set Report = Nothing
MsgBox Err.Description, vbCritical + vbOKOnly, "Impression"
End Sub