Crystal Report 10 and VB6...............

Posted on 2004-08-06
Medium Priority
Last Modified: 2012-06-27
Hi all,
        I am developing a small software which requires a couple of Reports to be generated...... Since I have no prior experience of developing in Crystal Reports, so a friend told me to follow these steps.......

1)  Develop a Report  "*.rpt"  in Crystal Report 10......Connect the Database to it........Change its design and add a few formula fields, text fields,Page Header, Page Footer etc. in the design within the Crystal Report IDE......

--> All of this is working perfectly and I am able to connect "Crystal Report 10" with the database and it all looks good.......

2) View the Report from within VB and then Print it...........

--> This is also working perfectly and I was able to view the Report from within VB and Print it........

but I have 2 main problems that I cant resolve.........

1) How to pass Parameters from VB to Crystal Report 10 created "*.rpt" file so that these parameters are displayed on the report when it is viewed ? I need help in VB (code as well as all references required) and in "Crystal Report 10" design of "*.rpt" file(What type of field should be used to receive parameters?).

2) I need to display fields from 2 different tables that are not linked together by any means...... i.e they have no relationship amongst them...... When I add field from one table(either) it works OK, but when I display data from two different tables it shows thousands of records which is obviously not correct.......A friend of mine told that when we display records from 2 tables which are not related to each other then it will give cartesian product and will not show the actual recods...(Is this correct ?)

So can I display records from two different tables that are have no relationship with each other(but have some common fields)  ?
As I have told earlier Databases is not my field so please if I have written something silly please ignore it.....
Please do tell me if I was not clear in explaining my point......(which is most probable)

Development Language : VB6
Database Used: Microsoft Access 2000
Crstal Report Ver. : 10
In VB I am using ADO to maipulate the Database........

Question by:imarshad
  • 4
  • 3
LVL 42

Accepted Solution

frodoman earned 2000 total points
ID: 11737725
For question #1, here is a sample application that contains everything you need.  References, code, etc.: http://support.businessobjects.com/communityCS/FilesAndUpdates/cr9_vb_rdc_parameter.exe.asp

It's written for CR9 but will work just fine with CR10 also as the RDC (the dynamic components) haven't changed significantly.  

For question #2, Crystal won't display data from two sources on the same report w/out problems.  The best way to do this is to use subreports.  Create the first report for 1 of the tables.  Then select insert->subreport and create a new subreport to pull the data for the other table.  The result of this is you have two separate reports, each tied to one table, but both within the same report 'container' so they can be viewed together.

Hope this helps - let me know if you need clarification on anything.

LVL 13

Author Comment

ID: 11737903
Thanks frodoman for the quick response......

The reply to question # 2 is really good and I am confident that it will solve lots of my problems.....
as far as question # 1 is concerned I will not be able to comment on it until tomorrow as I donot have Crystal Report installed on my home PC......I will check it tomorrow at my workplace and will let you know......

Imran Arshad
LVL 42

Expert Comment

ID: 11737987
No problem.

Question #1 is really two pieces.  First part is to create the parameter(s) in the crystal report that you need and then the second part is writing the vb code to pass values to those parameters.  You can get both from the sample application I linked you to but feel free to ask if anything isn't clear.


Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 13

Author Comment

ID: 11750430
OK Thanks a lot frodoman..........
Almost all things are working now.....Only got one problem yet to be solved.....

If I donot want to insert the full subreport into the primary report and only want to insert some formula fields from subreport into different parts of Primary Report(like some fields into Header and some into footer)......How can this be done ?

and sorry for the delay as I forgot that it was Weekend............

Imran Arshad
LVL 42

Expert Comment

ID: 11751860
>>> If I donot want to insert the full subreport into the primary report and only want to insert some formula fields from subreport into different parts of Primary Report

You can't do this - a subreport is either inserted or it isn't, there's no halfway.  You do have some options though.

Option #1 would be to create a subreport that only shows what you want to be shown and insert that report.  There's no reason a subreport has to have a whole bunch of information - I have subreports that show only a single field (say for example a total of all records of a specific type).  

Option #2 would be to use shared variables to pass values from your subreport to your main report.  The entire subreport must be inserted, but it can be suppressed so that it isn't visible.  To achieve the value passing you must declare the variables in your main report (commonly in the report header) with a formula like this:

shared numberVar MyNumber := 0;
shared stringVar MyText := '';

Now in your subreport you can simply assign values to these variables and then they can be used in your main report.  The catch is that the variables won't have a value until after the subreport has executed so if you want to use the value it must be below the subreport in your main report.

Hope that helps,

LVL 13

Author Comment

ID: 11752297
Thanks a lot frodoman........
You have been very helpful and prompt in answering the questions......a positive feedback from me.......

Imran Arshad
LVL 42

Expert Comment

ID: 11752311
Glad I could help!

Expert Comment

ID: 11978523
I know you are using vb6 in vb.net I created a dataset to handle both problems. One thing I did to display stuff on a form was one create a temp table to hold the data to be displayed. Plus I have beefed up my SQL queries and joined tables in the query.

George - www.ipdg3.com

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 19 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question