Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programming Subreport 1

Status
Not open for further replies.

jmerencilla

Programmer
Jul 17, 2002
123
0
0
SG
Hi. would you guys have some codes in VB (.Net) which i can use in programming my subreport? i have some codes here but it only appllies to a single main report. i tried searching the web looking for some codes that will initialize, set, and display my subreport for quite some time now but to no avail. i need to do these at run time because i use field definitions (ttx), and push method (i have a stored proc that fetches my data). Also, i'm using CR for .Net. thanks guys.

-jun
 
thanks synapsevampire. would you have any other sources? my method of generating a report is different from the one that you provided. i think this method is only applicable using the "pull method". so far, i have accomplished displaying a simple report using my method (push method where i have a dataset generated from a stored proc and programmatically set it at run time). errors arise when i include a subreport in it. i have a separate dataset for my main and subreport which makes it difficult for me to set my subreport programmatically because i honestly do not know how to do it. and to top it all, i'm using CR for .Net, not the enterprise edition of CR, some features are not included in .Net. it seems that the method that i used for my main report doesnt apply if i am to include a subreport. i really am in desparate need of some codes that will fast track me with my problem. thanks again. :)
 
Hi

Here is a sample code which I use to export a report to pdf using RDC. This is for VB6 and CR9.

Dim strPDFStore As String
Dim objRptOptions As ExportOptions
Dim objCrysApp As New CRAXDRT.Application
Dim objCrysRep As Report
Dim objCrysRep1 As Report
Dim objSubRep As Report
Dim adoCon As New ADODB.Connection
Dim adoCom As New ADODB.Command
Dim adoGoalSummary As ADODB.Recordset


Set objCrysRep = objCrysApp.OpenReport("C:\AssetConsolidated.rpt", 1) 'Open Main Report

adoCon.ConnectionString = connstring
adoCon.Open

Set adoCom.ActiveConnection = adoCon



Set objSubRep = objCrysRep.OpenSubreport("CurrentAsset.rpt") 'Open SubReport
adoCom.CommandText = "usp_rptSelectImage"
adoCom.CommandType = adCmdStoredProc
adoCom.Parameters(1).Value = 1

Set adoGoalSummary = New ADODB.Recordset
With adoGoalSummary
.CursorType = adOpenStatic
.CursorLocation = adUseClient
.LockType = adLockBatchOptimistic
End With
adoGoalSummary.Open adoCom
objSubRep.Database.Tables(1).SetDataSource adoGoalSummary


Set objRptOptions = Nothing
Set objCrysRep = Nothing
Set objCrysApp = Nothing

Regards
Krishna Kumar
 
Hi jmerencilla,

Just saw your post in Tek-tips dated 1 Jan, 03. I am facing a similar situation, would appreciate if you can give me some tips or some code that you followed to solve the problem.

Thanks,
-NK
 
hi NK! here are some codes which you may find helpful in running your subreport.

Dim rpt As New MyReport() 'MyReport is my main report; create an instance of it

Dim objSubreport As ReportDocument
objSubreport = rpt.OpenSubreport("my_subreport.rpt")
'my_subreport.rpt is my physical subreport file; create an instance of it

'you may manipulate your subreport here using objSubreport

Dim objDS as DataTable
'*********************
'create your dataset here
'*********************

objSubreport.SetDataSource(objDS)

now, provided that your subreport and main reports are properly joined at design, your should be able to see the desired output for your report. if you have question, feel free to ask me. :)

thanks.
-jun
 
Hi Jun,

Thanks a lot for the speed response. Initially when i thought of posting I was doubtful whether i would get any response.. as it was bit old post.. but you did respond and I appreciate that.

I went thru the code, and found that 'ReportDocument' data type is being used. I don't find 'ReportDocument' in my data types list, do i need to reference any particular interface for that? I already have the following references

1. Crystal Report Viewer Control
2. Crystal Reports 8.5 ActiveX Designer Design and Runtime Library
3. Crystal Reports 8.5 ActiveX Designer Run Time Library

In addition do i need to refer any other interface?

Guess you are using a .rpt file while creating the instance of the sunreport. In my case both the main report and sub report I used Crystal Designers(in VB ). TTx files which defines the recordset are used to provide the data which I fill at the runtime.
I assign the recordset to the report at the runtime in the Report_Initialize() event in the following way

Private Sub Report_Initialize()
AutoSetUnboundFieldSource crBMTName
Database.SetDataSource MyRecordset
'MyRecordset is the recordset which follows the schema specified in the TTx file

End Sub

These two reports i.e the main report and subreport work well independently, but now i want combine the both of them into one report.The subreport should not be On-demand report.

I have another issue too.. is there any way i can send 'Memo' data type using parameter. Actually i need to send Memo data from VB to crystal reports. Though I can send it through the recordset itself, I cannot use the recordset as my design won't support.

:) Please suggest some tips for these problems.

Thanks,
-NK
 
oppsss...i thought you were using CR for .Net? but i dont think that is the case. anyway, here are the references that i included in my project to access the ReportDocument object in VB .Net:

CrystalDecisions.CrystalReports.Engine


the ReportDocument object is included in the CrystalDecisions.CrystalReports.Engine. i dont know if this is the equivalent object that you need to reference to gain access to the ReportDocument object. but you may try it though.

with regards to your other issues, i dont think you'll be able to pass a memo datatype to a parameter. you can, however, create a series of formula that will contain some part of your parameter. be advised that a formula that contains a string value can only hold limited number of characters.

hope this will help you a bit. :)

-jun
 

Yeah I don't use CR for .Net, I use Crystal report 8.5 Sorry for not giving you that information, I should have done that.

In CR 8.5 I don't see any reference like CrystalDecisions.CrystalReports.Engine
I am sure this would be in some reference or the other.. Looks it's related with CR Engine

So I have created a new report which takes multiple recordsets.These recordsets are linked. Now I can display all the information with out using a subreport. Didn't have much time to do more R&D on this subreport topic.

The second problem i mentioned, yes i am aware of the size limitation of string value (already burnt my hands on that :) ) That's the actual reason why I am attemping to use memo fields.

Anyway this is how i worked around this problem:
As I mentioned above that I am using Linked multiple recordsets, I just added another recordset to the database which carries any other information that I want to send apart from the actual data. But this recordset is not linked to the other recordsets. Crystal Reports warned me that this is generally not supported as it creates multiple starting points. I just ignored it. Ran the report and it worked as i expected.(I should mention.. Some kind of relief :) ). But I wanted to know if you fore-see any problems in this solution.

cheers,
-NK
 
hello again. i have a question to ask. how do you create an instance of your report at run-time? i think the ReportDocument is the same class that you call to create an instance of a report. i just dont know how you'll instantiate your report using vb. eg.:

'VB .Net
Dim rpt As New MyReport() 'MyReport is my main report; create an instance of it

'this is the same as

Dim rpt as ReportDocument
rpt.Load("c:\MyReport.rpt")


you may use this same method with the subreport. so if you were able to create an instance of your main report in vb, you should also be able to create an instance of your subreport.

-jun
 

This is how I am using CR in my application..

Add References to the following libraries

1. Crystal Report Viewer Control
2. Crystal Reports 8.5 ActiveX Designer Design and Runtime Library
3. Crystal Reports 8.5 ActiveX Designer Run Time Library


'coding starts here

Public Report

Set Report = New CrysDsrGenSmry
'CrysDsrGenSmry is the Crystal designer in VB, the report(.rpt file) i want show would be embed into this designer, and this would be instantiated directly. I did this coz i don't want to distribute the .rpt file

CRViewer1.ReportSource = Report
'CRSmtViewer is the CRViewer control

'pass all the parameters if any
Report.ParameterFields(1).AddCurrentValue ("Report Parameter 1")

'preparing to show the report

CRViewer1.EnableGroupTree = False
CRViewer1.EnableProgressControl = False
CRViewer1.DisplayTabs = False

'show the report
CRViewer1.ViewReport



'when the statement Set Report = New CrysDsrGenSmry is executed the Initialize event in the designer is fired and this is the place where i bind the recordset which i would have created and filled already.


Private Sub Report_Initialize()
AutoSetUnboundFieldSource crBMTName
Database.SetDataSource MyRecordset
End Sub


'now when i try this to create a subreport the data for the subreport is not displayed at all

Dim m_SubReport As CRAXDDRT.Report

Set m_SubReport = CrysDsrGenSmry.OpenSubreport("CrysDsrsubreport")
'CrysDsrsubreport is the subreport designer, here i cannot use .rpt file as u mentioned coz of the same reason i mentioned above :)

m_SubReport.Database.SetDataSource SubRptRecordset


So I have tried to avoid using subreports which now satisfies my requirement also :) But I wanted to know how to use that.

About the second problem i am facing do you see any possible problems in future?

Thanks a lot for all this discussion.. In case you don't have any issues.. I would like to continue this in future.

Here is my mail id neo_kiran@yahoo.com

cheers :)
- Kiran

 
In reference to your question above "how to create an instance of your report at runtime" - HTH

private void CreateReport(string ReportName)
{
// the "Reports." is needed since that is how the GetTypes
// method returns the objects
ReportName = "Reports.rpt_" + ReportName;
//ReportName = ReportName;
oRpt = new CrystalDecisions.CrystalReports.Engine.ReportClass();
Assembly asmb = Assembly.LoadFrom(c_strAssemblyName);
System.Type[] tp = asmb.GetTypes();
int intReportIndex = 0;
foreach(Type definedType in tp)
{
intReportIndex++;
if (definedType.ToString() == ReportName)
{
intReportIndex--;
break;
}
}
oRpt = (CrystalDecisions.CrystalReports.Engine.ReportClass)asmb.CreateInstance(tp[intReportIndex].ToString());
oRpt.SetDataSource(dsReports);
//oRpt.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape;
CrystalReportViewer1.ReportSource = oRpt;
}

 
Hi Jun,

In the above posting I forgot to mention that the Assembly class comes from the Reflection namespace.

I followed the steps you outlined on 2/18/03 - and my architecture sounds exactly like yours - except C# instead of VB.Net. I am also using thePush model and using sprocs to create data sets. The sequence of my steps is first for main report and then for sub report
1. instantiate report
2. get data and setDataSource

then set the main report as the source of the viewer. I still do not see any data, only the headers in the sub-report. Please can u provide more details fromyour code.

Thanks in advance,

Amit Kohli
 
hi akohli. just a question. have you converted your dataset to a DataTable? i read somewhere before that you need to explicitly convert your dataset (the end-product of your stored procs) into a datatable first before you can use your data and push it to the report.

thanks,
jun
 
Hi Jun,
thanks for the quick response. Actually, I got it working. I was also trying to use the sproc as a datasource (so was using Push for the main report but pull model for the sub, trying to improve performance) - changed the sub to push as well and that worked just fine. I have created a number of standard reports and never had to convert the dataset to a datatable. So, empirically, the reports render just fine - just FYI.
Regards,

Amit
 
really Amit? i've been having some problems with the convertion because it takes too much time just to convert my dataset to datatable. i'll try to modify my code. thanks

jun
 

Hi,

This is a new post, I just wanted to try here as well.. :)

I would like to know how to use Memo datatype fields in the linked multiple recordsets.

The report's datasource is multiple recordsets logical linked to each other. The report is grouped (but not on the memo field). When the report is generated all the other information is shown as desired other than the data in the memo fields. In case of memo field, only the value in the first record keeps repeating in all the records on the report, where as the record seems to be having the correct data.

If the memo field is changed to string (just to test)it works.

Does Crystal report accept memo fileds in multiple recordsets?

Thanks in advance..
- NK
 
Hi NK,

Would really like to help but am unfamiliar with the 'memo' datatype. Just mentioning this cuz did not want to leave you wondering if u were going to get a useful response here. Hopefully Jun will be able to help you. Sorry and good luck.

Amit
 
Hi NK and Amit,
It's been a while since my last log-in here in tek-tips. sorry about that. Anyway, I have not tried using memo datatypes for my fields. Have you tried consulting with the knowledge base of crystal decisions( I usually consult it whenever i have a problem with my reports. and fortunately for me, most of my problems were resolved by this site. good luck with your search.

regards,
jun
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top