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

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........

LVL 13
Who is Participating?
frodomanConnect With a Mentor Commented:
For question #1, here is a sample application that contains everything you need.  References, code, etc.:

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.

imarshadAuthor Commented:
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
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.


Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

imarshadAuthor Commented:
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
>>> 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,

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

Imran Arshad
Glad I could help!
I know you are using vb6 in 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 -
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.