Tools Links Login

Run Crystal Reports within VB6 with Record Selecti

THis short piece of code illustrates how to imbed Crystal Reports into VB. While simple, it does not seem to be documented well anywhere.

Original Author: Steven Smith

Inputs

If using record selection (printing a selected record) v_choice is a variable to be passed to the record selection part of Crystal

Assumptions

Crystal OXC from VB application is on Form
You will have a menu option or command button to launch report

API Declarations

v_choice used for record selection (assign value to v_choice that matches field value)

Code

'' if using record selection for report on siingle record
' set v_choice as public string
' store your record selction field choice to v_choice
'*******************************************
'Add the crystal ocx object to form (will be named CrystalReport1)
' you can pass record selection
''NOTE
''Create the report in Crystal first and place the report in the same directory as your database.
'' Set the report location to same as database in Crystal
''This part is run from menu or command button
CrystalReport1.ReportSource = crptReport
CrystalReport1.ReportFileName = reportpath & "YOUR_REPORT_NAME.rpt"
'***This line only is using single record selection
CrystalReport1.ReplaceSelectionFormula ("{TABLENAME.FIELDNAME} =" & "'" & v_choice & "'")
'*********
CrystalReport1.WindowState = crptMaximized
CrystalReport1.PrintReport
CrystalReport1.PageZoom (50)

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 94 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.