Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

View Crystal Reports with Crviewer

Status
Not open for further replies.

shailesh32

Programmer
May 1, 2003
7
IN
How do we view pre complied crystal reports with crviewer in vb 6 with Crviewer.
I do not want to use CrystalReport .ocx control.
 
First you need a form with a "Crviever" control on it. You will need references to:

Crystal ActiveX Query Viewer 1.0 Type Library
Crystal Report 8 ActiveX Designer Design Time Library
Crystal Report 8 ActiveX Designer Run Time Library
Crystal Report Export
Crystal Reports 8 Library
Crystal Reports Viewer Control

My report viewer form is called frmViewCrystal and here's the code in it.

Option Explicit

Private mvarCalledBy As Form
Private WithEvents rpt As CRAXDRT.Report

Public Property Set Report(vData As CRAXDRT.Report)
Set rpt = vData
rpt.VerifyOnEveryPrint = True
End Property

Public Property Set CalledBy(vData As Form)
Set mvarCalledBy = vData
End Property


Private Sub CRViewer1_PrintButtonClicked(UseDefault As Boolean)
rpt.PrinterSetup &H0&
End Sub

Private Sub Form_Load()
Set Me.Icon = frmSelect.Icon
rpt.DisplayProgressDialog = True
With CRViewer1
.EnableProgressControl = True
.ReportSource = rpt
.ViewReport
End With
End Sub

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

Private Sub Form_Unload(Cancel As Integer)
Set rpt = Nothing
If Not mvarCalledBy Is Nothing Then Enable_Form mvarCalledBy
End Sub

Private Sub rpt_NoData(pCancel As Boolean)
TimedMessageBox "There is no data for this report", vbInformation, "No Data", 3
End Sub

Where "Crviewer1" is the Crystal Reports Viewer Control.

Now, to actually display a report in frmViewCrystal
NOTE: This is heavily edited. My "real" FormatCrystalReport sub has a lot of code related to specific formatting, filtering, changing data sources, etc. specific to the reports that I use. Here I'm providing only the basic stuff that you need to display a canned report.


Public Sub FormatCrystalReport(Rep_Name As String)

Dim rdApp As CRAXDRT.Application
Dim rpt As CRAXDRT.Report

Set rdApp = CreateObject("CrystalRuntime.Application")
Set rpt = rdApp.OpenReport(Rep_Path & Rep_Name)

' You can set properties in 'rpt' to control all sorts of stuff including
' the path, filter clauses, field values, etc.
' Check the Crystal documentation for the Properties, Methods and Events for the Report Object.


Dim Frm As Form
Set Frm = New frmViewCrystal
Set Frm.Report = rpt
Set Frm.CalledBy = Nothing
Frm.Show
Set rpt = Nothing
Set rdApp = Nothing

End Sub


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top