Null parameter in sub report causes sub-sub report to fail - activereports

I am using active reports version 3.2
I have a report with sub report A.
Inside sub report A there is sub report B.
Report passes parameter X to sub report A
Sub report A passes parameter Y sub report B
If the result of subreport A is empty then B fails throwing a null exception error while doing some regex.
I have tried several methods to fix this.
I have added a default parameter, this still fails.
<%'OtherModuleRef'|Enter a module|'00000000-0000-0000-0000-000000000000'|S|False%>
I have changed the SQL to detect a null and generate a valid query.
This also fails.
What else can I try?

I could not find a good way of fixing this.
Tho I did invent a workaround.
In the first sub report, on the no data event add the field the sub-sub report needs and set it to a "null" value. The report will work as normal if there is data and work if there is no data in the sub report.
Sub ActiveReport_NoData
rpt.Sections("Detail1").Visible = False
rpt.Fields.Add("OtherModuleRef")
rpt.Fields("OtherModuleRef").Value = "00000000-0000-0000-0000-000000000000"
End Sub

Related

Invalid Name Error - Crystal Reports in VB6

I'm trying to set the title of a crystal report in VB6, but I keep being shown an error.
The parameter field that I want to set the text of is called txtTitle.
However, when running this code, it gives an error saying
Invalid Name
If opt_sales_ledger.Value = True Then
crxReport.ParameterFields.GetItemByName("txtTitle").AddCurrentValue ("List of Sales Ledger Accounts")
ElseIf opt_purchase_ledger.Value = True Then
crxReport.ParameterFields.GetItemByName("txtTitle").AddCurrentValue ("List of Purchase Ledger Accounts")
End If
What's causing the error?
Crystal is looking for a "parameter" type field called "txtTitle" and it cannot locate it. I usually use formulas for this purpose, in other words "txtTitle" would be a formula in the report and defined and/or initialized as a stringVar
Try to use this way:
crxReport.ParameterFields(1).AddCurrentValue ("your_first_parameter_value")
crxReport.ParameterFields(2).AddCurrentValue ("your_second_parameter_value")
Good luck!

VB.NET 2010 RDLC Subreport "Data retrieval failed for the subreport"

Using VB.NET 2010 and SQL Server 2008 R2.
I have inherited an application with a RDLC report. I have not used those before. The report was created and works fine but the originator left out a set of data, a subreport for the "parent" record reported on.
I have tried to add a subreport, point the input parameters of the main to the sub(they use same information). Have the sub use a Dataset that points to a Stored procedure and display the results.
Any attempt to execute (and display) sub report data fails with the message
Data retrieval failed for subreport....located at....Please check the log files for more information.
Off what/where are the log files located?
I can pass in params and as long as I add a dataset w/a stored procedure, I can see the params if I put on report. If I add the stored procedure ...Nothing. I tried a fix found on internet to create a Copy of the XSD's stored procedure call... but that didn't work either.
Main report works fine without Sub.
Thoughts?
What am I missing?
Shouldn't I be able to add a subreport, link up the parameters and have subreport display related information?
Here is my code to call main report:
Dim adapter As New SqlClient.SqlDataAdapter
Dim table As New DataTable
Try
Cursor.Current = Cursors.WaitCursor
ReportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local
ReportViewer1.LocalReport.ReportPath = Application.StartupPath & "\IndividualInterviewerDataReport.rdlc"
Dim ReportParameters(5) As Microsoft.Reporting.WinForms.ReportParameter
ReportParameters(0) = New Microsoft.Reporting.WinForms.ReportParameter("SurveyName", frmMain.SurveyName)
ReportParameters(1) = New Microsoft.Reporting.WinForms.ReportParameter("Interviewer", InterviewerId)
ReportParameters(2) = New Microsoft.Reporting.WinForms.ReportParameter("Panel", PanelMonth)
'
'
ReportParameters(3) = New Microsoft.Reporting.WinForms.ReportParameter("- Version: " + ProductVersion)
ReportParameters(4) = New Microsoft.Reporting.WinForms.ReportParameter("PanelYear", PanelYear)
ReportParameters(5) = New Microsoft.Reporting.WinForms.ReportParameter("SurveyNbr", frmMain.SurveyNum)
ReportViewer1.LocalReport.SetParameters(ReportParameters)
ReportViewer1.ShowPrintButton = True
ReportViewer1.ZoomPercent = 100
Me.spInterviewerDataByPanelTableAdapter.Connection.ConnectionString = My.Settings.DBConnection
Me.spInterviewerDataByPanelTableAdapter.Fill(Me.CodingControlDataSet.spInterviewerDataByPanel, frmMain.SurveyNum, PanelYear, PanelMonth, InterviewerId)
Me.ReportViewer1.RefreshReport()
If I'm remembering correctly, you'll need to handle the SubreportProcessing event of the LocalReport object, and set the subreport data there. You do this by setting a property of the EventArgs parameter for the event handler.
Here's some code (adapted from Microsoft documentation):
'In your report setup code'
AddHandler Me.ReportViewer1.LocalReport.SubreportProcessing, _
AddressOf DemoSubreportProcessingEventHandler
'Event hander
Public Sub DemoSubreportProcessingEventHandler(ByVal sender As Object, _
ByVal e As SubreportProcessingEventArgs)
e.DataSources.Add(New ReportDataSource("DatasetNameInReport", MyDataTable ))
End Sub

SAP Subreport will print to PDF but not to viewer or printer

I have two different SAP Crystal Reports, one has sub reports and the other doesn't. For whatever reason the simple CR prints to the printer, to PDF and to the viewer just fine. The CR with subreports only prints to PDF for whatever reason. This is leading me to believe there's nothing inherently wrong with the report itself otherwise it wouldn't work when I save to PDF.
A snippet of my code is below (in VB):
Select Case PrintMedia
Case PrintType.Printer
crOrderPrintout.PrintToPrinter(1, False, 0, 0)
Case PrintType.Viewer
Dim frmReportViewer As New frmReportViewer
frmReportViewer.CrystalReportViewer1.ReportSource = crOrderPrintout
frmReportViewer.ShowDialog()
Case PrintType.File
crOrderPrintout.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, String.Format("C:\Documents and Settings\{0}\Desktop\{1}.pdf", mdlSharedVars.StripDomainFromFullUsername(WindowsIdentity.GetCurrent.Name), ReceiptID))
Case Else
crOrderPrintout.PrintToPrinter(1, False, 0, 0)
End Select
For clarification the PrintMedia is a variable whose type is a custom enum of mine, PrintType.
When I try to show the report with the subreport in the viewer or print to printer I get a "Index was out of range. Must be non-negative and less than the size of the collection.
Parameter: index." error. Yet the simple, non-subreport CR works just fine regardless of the PrintMedia.
Don't suppose anyone has any ideas??
After fighting with this for longer than I care to imagine, it turns out there was a problem with one of the fields in the crystal report display string. Basically I started the report from scratch, adding in piece by piece trying to isolate the error.
Can you try the report in an off the shelf Crystal viewer or Crystal Reports itself? Does it work?
Maybe try setting the printer options in page setup to "No Printer (Optimize for screen display)"

Crystal reports 11 : blank field bombs the report

I'm creating a invoice crystal report for sage mas 500 AR module. In it, I'm attempting to add the tarinvoice.balance field with the following formula:
if {tarPrintInvcHdrWrk.Posted} = 1 then
ToText({tarInvoice.Balance})
I'm assuming that when the {tarPrintInvcHdrWrk.Posted} = 1 conditional statement holds FALSE, it doesn't attempt to pull the invoice field because when I remove the formula from the report, the form displays correctly without it.
When the conditional statement renders true in the report, the balance fields behaves correctly. However, with the formula renders FALSE in the CR form, the entire crystal report bombs and displays blank. Any ideas why or what I'm doing wrong?
Just tried setting everything to zero and the report still bombs. I'm starting to think its more of a query error in the report. I wish there was a way to exclude the field in the query when posted = 0.
With tarinvoice.balance removed when the posted = 0, the report works fine.
With tarinvoice.balance included and posted = 1, report works fine.
With tarinvoice.balance included and posted =0, report bombs.
I believe the conditional statement fails immediately if you encounter a NULL, so your formula needs to test IsNull({tarPrintInvcHdrWrk.Posted}) before it tests equality with "1".
You can change the way Crystal handles a null value for a value in a formula. At the top of the Formula Workshop there is a drop down box that usually says "Exceptions For Nulls".
Change this to the other option "Default Values For Nulls" and your formula should no longer bomb out. You used to be able to specify the what the default values applied were, but more recent versions of Crystal have these hard coded.
Search the help for "Null Treatment" for a table showing them.
I modified the formula to this:
if isnull({tarPrintInvcHdrWrk.Posted}) = FALSE then
if {tarPrintInvcHdrWrk.Posted} = 1 then
if isnull({tarInvoice.Balance}) = FALSE then
ToText({tarInvoice.Balance})
else
"0.00"
else
"0.0"
else
"0"
The crystal report still bombs.. Nevertheless, it does show "0" in the appropriate space.
I saw a suggestion on Exp.Exch to try putting the field into a variable before converting it to text.
e.g.
NumberVar InvoiceBalance;
If isnull({tarInvoice.Balance}) then
InvoiceBalance := 0
Else
InvoiceBalance := {tarInvoice.Balance};
If {tarPrintInvcHdrWrk.Posted} = 1 then
ToText(InvoiceBalance);
I also tried to recreate your problem, since I have see similar things before.
No luck though trying with CR 8.5 & XI R2. Perhpas it has to do with linked tables as well, since I only tried on a simple single table.
I have also seen similar behaviour when using a formula within a Running Total - they do not like nulls at all!
If you put {tarInvoice.Balance} directly on report (into details "debug" section - often needed, don't forget supress it in production :)), what values it displays or does report become empty?
Maybe you have Suppress If Blank section on your report. Try to put: Else " "
if isnull({tarPrintInvcHdrWrk.Posted}) or {tarPrintInvcHdrWrk.Posted}=0 then
" "
else
if {tarPrintInvcHdrWrk.Posted} = 1 then
ToText({tarInvoice.Balance})
else
" "
I have trouble with this kind of field when making reports to export to excel. A field with no data in will pull all columns to the right of it over to "fill the gap".

Crystal Reports - Default Parameters

In Crystal reports, you can define default values for the report parameters.
For example, I might have a date range and set a default start of 12/01/2008 and a default end of 12/31/2008.
Is it possible to modify these defaults at runtime? For example:
1 - Default to the first and last days of the current month?
2 - Default to the first and last days of a proprietary company fiscal calendar? (i.e., look it up in a database)
3 - First & Last days of the current year?
You get the point. Is this possible? I'd even be open to a solution that involved running an external application to reach into the reports and modify them, if anyone knows how to do that.
Edit:
To answer the question posed by Philippe Grondier, most of these reports are run from inside an application. I was hoping for something simpler than manipulating the crystal object at runtime; I have my hands full right now with figuring out other parts of that API. I might take a look in the future, though.
Are you planning to run your crystal report from the crystal reports interface or as an add-in embedded in another program (you can for example use the Crystal Reports ActiveX Designer Runtime Support - craxdrt.dll - in VB code) ? In this last case, it is possible to manipulate every object of the report before launching it. Objects such as parameters can then be updated according to your needs.
As a simple example of such runtime update, my report printing routine will allways check if there is a field named "printedBy" in the report. In case this field is found, its value will be settled to the the domain name of the user that requests the report and will be printed out.
At an higher level, you can even reshape the report SQL string to add specific filters that can be inherited from your code. By doing so you might not even need parameters anymore: let your code add the filtering values 'on the fly'
EDIT: some code examples:
(m_rapport is a CRAXDRT.report object, ActiveSession is my current session object)
If m_rapport.ParameterFields.Count > 0 Then
For i = 1 To m_rapport.ParameterFields.Count
If m_rapport.ParameterFields(i).Name = "{?PUB_DateDebutPeriode}" Then
m_rapport.ParameterFields(i).AddCurrentValue CDate(DateValue(sessionActive.dateDebutPeriode))
End If
If m_rapport.ParameterFields(i).Name = "{?PUB_DateFinPeriode}" Then
m_rapport.ParameterFields(i).AddCurrentValue CDate(DateValue(sessionActive.dateFinPeriode))
End If
If m_rapport.ParameterFields(i).Name = "{?PUB_id_Personne}" Then
m_rapport.ParameterFields(i).AddCurrentValue StringFromGUID(clientActif.id_Personne)
End If
Next i
Endif
I also have another function to change report's datasource at runtime, so that reports can be executed on different servers/locations.
Read my posting Crystal Reports: Named-Date-Range Parameters. Maybe you'll be able to leverage this technique for your purposes.