SAP Knowledge Base Article - Public

1218364 - How to add a report viewer to a Visual Basic application programmatically

Symptom

How can you add a Crystal Report Viewer to a Microsoft Visual Basic (VB) application programmatically?

Resolution

To add a Crystal report viewer to a VB application programmatically, use the following code:

NOTE: The following code will add the ActiveX viewer to a VB application using the Crystal Report Designer Component (RDC). 

Dim Report As New CrystalReport1
Dim crViewer As Object
Private Sub Form_Load()
'Uncomment the 'Set crViewer' line that corresponds to the version you are using.

  'Create and add a version 8.5 Crystal Report Viewer.
'Set crViewer = Me.Controls.Add("CRViewer.CRViewer", "crViewer")

  'Create and add a version 9 Crystal Report Viewer.
'Set crViewer = Me.Controls.Add("CRViewer9.CRViewer", "crViewer")

  'Create and add a version 10.0 Crystal Report Viewer.
'Set crViewer = Me.Controls.Add("CrystalReports10.ActiveXReportViewer.1", "crViewer")

  'Create and add a version 11.0 Crystal Report Viewer.
'Set crViewer = Me.Controls.Add("CrystalReports11.ActiveXReportViewer.1", "crViewer")

  With crViewer
.Visible = True
.ReportSource = Report
.ViewReport
.Zoom 100
End With
End Sub

  Private Sub Form_Resize()
With crViewer
.Top = 0
.Left = 0
.Height = Me.ScaleHeight
.Width = Me.ScaleWidth
End With
End Sub
 

Keywords

11 ACTIVE X PREVIEW RPT DSR CRAXDRT CRAXDDRT CRAXDUI AUTOMATION SERVER Report Designer Component ActiveX viewer Adding viewer programmatically , c2017059 , KBA , BI-RA-CR , Crystal Reports designer or Business View Manager , Problem

Product

SAP Crystal Reports XI ; SAP Crystal Reports XI R2