Invalid Name Error - Crystal Reports in VB6 - crystal-reports

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!

Related

Crystal Reports - Command Line CRExport.exe Odd Formula Error

I built a report in crystal reports (version 11.5.12.1838 - yes it's old, but I have no ability to upgrade it, it comes with the software we use for cash reporting).
I have this formula:
if (DateTime({#Date1}) = Datetime({rpcRGHL5DayBalanceView;1.1date}))
then
{rpcRGHL5DayBalanceView;1.1}
else
999999999999.99
The report runs and exports fine within crystal as well as the application we use. However, when using CrExport.exe (free command line tool) the report fails to generate and provides this error.
Error : A string is required here. Details: errorKind Error in File RGHL-5DayBalanceView {25B5C1DE-4C71-4A2D-816E-165F95A6B03B}.rpt:
Error in formula Balance1:
'if (DateTime({#Date1}) = Datetime({rpcRGHL5DayBalanceView;1.1date}))
then ' A string is required here. Details: errorKind
This seems to happen when the parameter I pass in via the command line differs from the stored value on the report. If I pass in the same value, the report generates, but the data is not updated. The data that was saved on the report is what I get.
I use this CrExport.exe with several other reports with no problem. Not sure if it's a bug in the command line tool or not.
Also, if I change the values from numeric to text via this code.
if (DateTime({#Date1}) = Datetime({rpcRGHL5DayBalanceView;1.1date}))
then
ToText({rpcRGHL5DayBalanceView;1.1},0)
else
ToText(999999999999.99)
Then I get this error from the command line program.
Error : Too many arguments have been given to this function. Details: errorKind
Error in File RGHL-5DayBalanceView {98633D00-5B70-4B7D-839C-1D0CEB359AE9}.rpt:
Error in formula Balance1: 'if (DateTime({#Date1}) = Datetime({rpcRGHL5DayBalanceView;1.1date})) then
'Too many arguments have been given to this function.
Details: errorKind
Any help is much appreciated. Let me know if more information is needed and I will do what I can to provide it.
try like this:
if (DateTime(CStr({#Date1})) = Datetime({rpcRGHL5DayBalanceView;1.1date}))
then
ToText(CStr({rpcRGHL5DayBalanceView;1.1}),0)
else
ToText(999999999999.99)

INSTR in Crystal

We are using this function to filter data by program codes entered, if nothing is entered return all?
Can any one please explain this Crystal function, and how Crystal works with it? Mainly the last statement.
Here is some information that might be useful.
{?Program} ==> Parameter to accept different programs codes in the following form
303&410&110
{Command.program_code} ==> Field were program code is stored
if ({?Program} = "")
then true
else
(INSTR("&" & {?Program} &"&", "&"& {Command.program_code} & "&")>0)
Thanks...

Formatting date parameter in iReport

I want to format a date parameter in my report. The date looks like this in my database and my report "yyyy-mm-dd" (2014-04-17 for example). I tried to do it with that line of Code which I always saw on other posts:
new SimpleDateFormat("dd/MM/yyyy").format($P{Startdatum})
That doesn't work of course and I am getting this error:
Error filling print... Error evaluating expression : 
    Source text : new SimpleDateFormat("dd/MM/yyyy").format($P{Startdatum})
net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : 
    Source text : new SimpleDateFormat("dd/MM/yyyy").format($P{Startdatum})
    at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:203)
    at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:591)
    at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:559)
    at net.sf.jasperreports.engine.fill.JRFillElement.evaluateExpression(JRFillElement.java:966)
    at net.sf.jasperreports.engine.fill.JRFillTextField.evaluateText(JRFillTextField.java:456)
    at net.sf.jasperreports.engine.fill.JRFillTextField.evaluate(JRFillTextField.java:440)
    at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:259)
    at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:455)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillBandNoOverflow(JRVerticalFiller.java:457)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillPageHeader(JRVerticalFiller.java:421)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:282)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:151)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:909)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:822)
    at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:61)
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:446)
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:276)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:745)
    at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:891)
    at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572)
    at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997)
Caused by: java.lang.IllegalArgumentException: Cannot format given Object as a Date
    at java.text.DateFormat.format(DateFormat.java:301)     at java.text.Format.format(Format.java:157)     at Berichtsheft_1397742638211_397211.evaluate(Berichtsheft_1397742638211_397211:223)
    at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:190)
    ... 20 more Print not filled. Try to use an EmptyDataSource...
I am using this parameter for one of my Queries ! Could that be the reason for the error ? Or is the syntax simply false ? Or is there even any other reason for this error ?
Try to use just parameter name like this:-
new SimpleDateFormat("dd/MM/yyyy").format($F{Startdatum})
and check the report "Language" in property panel you should change it to "java".
To change the report language go to Windows --> Report Inspector- and click on the report name and then --> Windows--> Properties.
Here in down the panel you can select the Language.
Try to use that expression instead
new SimpleDateFormat("dd/MM/yyyy").parse($P{Startdatum})

I need the details section to suppress if a custom date field is blank in Crystal Reports

I have the following suppression formula in the details section:
{JCJM.udRough} <= #1/1/2013 12:00#
AND
{JCJM.udTrim} <= #1/1/2013 12:00#
and it works. However, I also need it to suppress if the udRough or udTrim field is blank. When I try to add
OR {JCJM.udRough}=""
it says that a date-time is expected where the blank quotes are.
Can someone please help?
As a general rule in CR, if a field can be null then you should explicitly check for that case first in a formula, otherwise it will not evaluate properly. Otherwise, CR will treat it like an unhandled exception.
So in your case, CR is short-circuit evaluating the expression {JCJM.udRough}<=#1/1/2013 12:00# as the very first thing, sees that the field is null, and stops evaluating the rest of the formula since it has encountered an exception.
What you need is:
(isnull({JCJM.udRough}) or {JCJM.udRough} <= #1/1/2013 12:00#)
and (isnull({JCJM.udTrim}) or {JCJM.udTrim} <= #1/1/2013 12:00#)
Try
if ISNULL({JCJM.udRough})
Then true
else false
This is from my understanding from your question if you are searching for something different let me know will try to answer it.

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