Search Tools Links Login

Load and view Crystal Reports XI external RPT files.


Visual Basic 6, or VB Classic

Allows you to load and view any outside XI report file from your VB6 code.

Original Author: OASyS

I had decided to publish the following code into PSC since I'm having looking for it for weeks and I had not found any similar code and explanation in whole Internet. The following code is really a compilation of dozens of manuals, codes, forum messages and so forth. I hope it could be usefull to you. If you agree, please vote...

How to Open an External Crystal XI Report in VB6

1) You must enable the "Crystal ActiveX Report Viewer Library 11.0" in the CONTROLS tab of PROJECT - COMPONENTS. A new object will appear in the VB6 TOOLBOX section (the REPORT VIEWER ocx). 

2) Create a new form named "FRMCRYSTAL" (frmCrystal.frm) and add the Crystal object into it. The report viewer window will appear inside your form. Put the following lines in its LOAD event:

CRViewer1.Top = 0
CRViewer1.Left = 0
CRViewer1.Height = ScaleHeight
CRViewer1.Width = ScaleWidth

Set its "VISIBLE" property to FALSE and close the form.

2) To open and display an external Crystal XI report, you may use these lines in any place of your program:

I'll divide the task in 4:

2.1) point and open the report;
2.2) change the report parameters;
2.3) change the report SQL query; and
2.4) view the report.

2.1)  Let's open the external file.The second parameter ("1") means NO-EXCLUSIVE open or TEMP-COPY open.

If you change for zero (EXCLUSIVE), the report will open just once per session.

Dim MyApp As New CRAXDRT.Application
Dim MyRpt As New CRAXDRT.Report
Set MyRpt = MyApp.OpenReport("c:windowssample.rpt", 1)

2.2) Let's change some parameters. Interesting to note the FORMULAFIELD syntax, where I can name my text-fields instead to utilize their indexes (easier to work on than the Business Solution's Crystal manual).  Obviously, the name between parenteses must reflect the exact formula/text/field name. In that example, the formulas are STRING type.

MyRpt.ReportTitle = "That's my Title!"
MyRpt.FormulaFields.GetItemByName("InitialDate").Text = "'Initial Day: " & dr1(0).Value & "' "
MyRpt.FormulaFields.GetItemByName("FinalDate").Text = "'Final Day: " & dr1(1).Value & "' "

2.3) Change the report SQL query...

x = 100 : y = 1000
MyRpt.SQLQueryString = "select * from dropouts where InitialIssue <= " & x & "and FinalIssue >= " & y

2.4) Finally, log on your server and database. Since your report already exist and has the appropriated fields and layout, you must use the same database and login info present in the report. In my example, you must change the names for your correct ones.

MyRpt.Database.Tables(1).SetLogOnInfo "","", "", ""
MyRpt.Database.Verify      'required!!!
' And voilá !!! Show the report!!!
frmCrystal.CRViewer1.ReportSource = MyRpt
frmCrystal.Show
frmCrystal.CRViewer1.ViewReport
' Clear memo...
Set MyRpt = Nothing
Set MyApp = Nothing

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 202 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.