Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Design w/ Subreports Post Reply Post New Topic
Author Message
ninjatalon
Newbie
Newbie


Joined: 17 Oct 2012
Online Status: Offline
Posts: 4
Quote ninjatalon Replybullet Topic: Design w/ Subreports
     Posted: 17 Oct 2012 at 4:55am
Hello. My name is Danny, I've have come across this website and it seems I have found many answers before regarding Crystal Reports. I have never taken any courses for Crystal Reports or Database Programming. But I have taught myself the basics.
I have searched but haven't found the answer, and this is why i'm posting. I have a report that outputs information of 180 clients. A Client per page. In each page there is an abundance of information, but i'm requiring to use a sub-report. In the sub-report I have to output more information from the client, and that's where I come to a roadblock. I'm unable to make the subreport to be unique to every page. I need to link a table for each subreport in the report.

EX.
objRpt.SetDataSource(reporttable)

1st page-1st client
objRpt.Subreports(0).SetDataSource(tblsubreport1)
2nd page-2nd client
objRpt.Subreports(0).SetDataSource(tblsubreport2)
3rd page-3rd client
objRpt.Subreports(0).SetDataSource(tblsubreport3)

Please Help. Thanks.
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 17 Oct 2012 at 5:59am
You can't do it this way.  Your subreport can have only one datasource.  The subreport should have a "generic" query that will pull in the data for every client if it's not filtered and you should use the link from the main report as a filter to pull in the data for that specific client.
Does your subreport use linked tables or are you using a command in it to get the data?
 
-Dell
IP IP Logged
ninjatalon
Newbie
Newbie


Joined: 17 Oct 2012
Online Status: Offline
Posts: 4
Quote ninjatalon Replybullet Posted: 17 Oct 2012 at 6:05am
I'm using mysql query to make each datatable from a different database. So in other words I should rewrite my query to union all client's detailed information Then filter the results using the Clients ID by passing a parameter to the subreport from the main report?
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 17 Oct 2012 at 6:31am
So the tables are in different databases?  You don't mention what type of database you're using, but in Oracle and SQL Server there is the concept of "Database Links" where you can query data from one database while logged in to another.
 
If something like this is available to you and you have a way of determining in the Main Report which database to "link" to for the subreport (whether you have a field in the data from the main report or you create formula that will do this) then you might be able to do the following:
 
1.  Use a command in your subreport.  Using Oracle syntax, it might look something like this (assuming the table name is the same in every database)
 
Select
 Field1,
 Field2,
 ...
 Fieldn
from MyTable@{?DBLINK}
where Field1 = '{?Some Parameter}'
 
2.  Create the two parameters - DBLINK and Some Parameter in the Command Editor (DO NOT create them in the subreport Field Explorer - they won't work with the command!)
 
3.  In the main report, go to the subreport links.  Select the field or formula in the main report that contains the database link information.  Turn off "Select data in subreport based on field:".  In the drop-down on the bottom left, select the {?DBLINK} parameter you set up in the command.  Do the same thing for any other parameters you want to pass in from the main report.
 
This should work because parameters in a command are not really parameters in a database query sense, Crystal will just replace them with the value that is set for the parameter.  However, I don't guarantee it will work as I have never actually tried doing this.
 
-Dell
IP IP Logged
ninjatalon
Newbie
Newbie


Joined: 17 Oct 2012
Online Status: Offline
Posts: 4
Quote ninjatalon Replybullet Posted: 17 Oct 2012 at 9:05am
Thank you. I believe your first post was enough to help me get an idea. I will gather all my info into one table then filter out what is needed. I'm using vb.net and MySql. Thanks now I just have to code it out.
IP IP Logged
ninjatalon
Newbie
Newbie


Joined: 17 Oct 2012
Online Status: Offline
Posts: 4
Quote ninjatalon Replybullet Posted: 17 Oct 2012 at 12:25pm
I have just completed my report. Thank you very much for helping me out. I ended up putting all the clients information into one table then filtered it out using subreport links.

Edited by ninjatalon - 17 Oct 2012 at 12:25pm
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum