VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Load and view Crystal Reports XI external RPT files.

by OASyS (1 Submission)
Category: Databases/Data Access/DAO/ADO
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (5 Votes)

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

Rate Load and view Crystal Reports XI external RPT files.

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:\windows\sample.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 "<server>", 
"<database>", "<login>", "<password>"

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



 


Download this snippet    Add to My Saved Code

Load and view Crystal Reports XI external RPT files. Comments

No comments have been posted about Load and view Crystal Reports XI external RPT files.. Why not be the first to post a comment about Load and view Crystal Reports XI external RPT files..

Post your comment

Subject:
Message:
0/1000 characters