Deleting fields without losing (linked) column headings

Tuesday 24 December 2019 @ 5:14 pm

Whenever you drag a new database or formula field onto the details band, Crystal will add a column heading for you, automatically. This heading is just a text object but it will stay internally linked to that field. If you move the field horizontally, or change its width, the heading will adjust to match.  If you delete the field, the heading disappears as well.

This can sometimes present a challenge. For example, when you have formatted and aligned column headings and you need to replace the fields below them. When you delete the original fields the headings will also be deleted and then you have to recreate them and reformat them.  I was in this situation twice in the past few days. In one case I had to replace a group of tables with a SQL command, in the other I replaced a SQL command with a subreport. In both cases the database fields on the report had to be replaced. And as soon as I deleted the original fields I saw that the headings also went away. I didn’t want to recreate the headings to match the old ones, so I hit undo and did some experimenting.  I learned two things that allowed me to keep my original headings in place even after the original fields are deleted:

  1. If you copy the headings and paste a second copy of them somewhere else on the report, Crystal will only delete one set.
  2. If the new headings are in a separate section Crystal will delete the headings in the higher section.

So my new approach for this scenario is to:

  • Split the section that contains the headings to create a new temporary subsection.
  • Drag the new subsection to be above the original section.
  • Copy the headings and paste the copies into the new blank section.
  • Insert the new fields into the new subsection (so they won’t create new headings)
  • Use the format painter to format the new fields based on the format of the originals.
  • Use the menu (format > make same size) to size the new fields to match the originals.
  • Delete the original fields, which should delete the new headings in the higher section.
  • Move the new fields to the original section and align them with the original headings.
  • Delete the temporary subsection.

This process adds a few extra steps, but it keeps your original headings exactly as they were and allows the new fields to look exactly like the ones that they replaced.





PDF problems with Viewpoint’s Spectrum Software

Wednesday 18 December 2019 @ 10:28 pm

Any time Crystal Reports exports to PDF there is a slight reduction in font size. So when a customer complained that their fonts were exporting inconsistently to PDF, I figured it would center around this topic.  But, what I found was something different. The report was being run from within Viewpoint’s Spectrum Software for construction. The report looked fine if we exported it to RPT format and opened it in the Crystal Reports designer, but the PDF version had inconsistent font sizes.

One example was a large block of text with four paragraphs. It was all formatted with the same font and the same size in Crystal. In PDF format the first paragraph was in one size and all the other paragraphs were in a different size. I cut the first paragraph out to make it a separate text object and left the remaining three paragraphs in one text object.  But the font change just moved down to the next paragraph break.  I had to make each paragraph it’s own text object to avoid font changes.

A second problem was that text objects and field objects would end up being reduced by different amounts, even though they started out the same size. For example, just before the text objects was a database memo field that was supposed be the same font size. If I started them both at font size 9.5 in the report, the memo field would end up at 8.5 while the text object would end up at 8.  If reduced the memo field to 9 the font would end up as 7.5. I tried several other combinations and couldn’t find one where the text objects and fields would end up the same size in the PDF.

The odd part was that I couldn’t replicate any of these problems in my local environment.  I opened their rpt file saved with their data in my Crystal Reports designer and it exported just fine. I even tried it in Crystal v10 which is 15 years old and uses Adobe 4.0 format.  It still exported here with consistent font  sizes. So it sounds like this might have something to do with the runtime environment associated with Spectrum.

Conclusion: If you are using Viewpoint’s Spectrum Software, watch out for PDF font sizes.  If you need help with these issues, give me a call.





Sage 50 GetPeach() functions in Windows 10

Monday 9 December 2019 @ 7:38 pm

For some reason the combination of Sage 50 (PeachTree) and Windows 10 generated many calls from customers.  Most of these calls were for reports that used the special GetPeach() functions and that stopped working.  These functions have come with Sage/PeachTree for years. I was told by several Sage consultants that these functions would no longer work in the current versions of Sage 50.  But one of my customers ended up solving the problem on his own and has allowed me to share what he found (he didn’t want to be cited).

So here is how he got these functions working again:

  1. A system PATH variable must be assigned to C:\Program Files (x86)\Sage\Peachtree. This folder contains the DDFs (data dictionary files) for the interface between Peachtree and Crystal Reports and other special functions. Without these DDFs, any effort to run a report containing GetPeach() functions will fail with the error message “The Specified Module Could Not Be Found”.
  2. In a single user environment U2LPeach.dll and the associated .ini file (U2LPeach.ini) must be included in the folder C:\Windows\Crystal. This is the default location the files are placed by Sage 50 when data functions are updated.
  3. If operating in a terminal services environment, U2LPeach.dll and the associated .ini file (U2LPeach.ini) must be included in C:\Users\\Windows\Crystal.
  4. When U2LPeach.dll is loaded correctly, the .dll will appear in the list of dlls loaded by Crystal Reports. This list can be found by going to “Help > About Crystal Reports” and clicking “more information”. Alternately you can edit any formula and look in the additional functions node for the GetPeach functions.

If you are having problems with Sage 50, and the above doesn’t help you, let me know. I have several colleagues who are Sage 50 specialists so we should be able to resolve it for you.





Crystal Reports formula function libraries (2019)

Wednesday 27 November 2019 @ 11:10 pm

It is time for my annual comparison of formula function libraries. If you aren’t familiar with User Function Libraries (or UFLs) they are DLL files that add new formula functions to your Crystal Reports formula editor. With these functions your formulas can do some pretty amazing things like:

1) Carry values from today’s report to tomorrow’s report
2) Carry values from one report to another.
3) Append lines of text to an external text file.
4) Automatically copy a value to the clipboard.
5) Check the user name of the user running the report.
6) See if a file or folder exists (on your network or on the internet).
7) Rename/copy/delete a file on your hard drive or network drive.
8) Launch an application or run a batch file.
9) Execute a SQL statement (Select/Insert/Delete).
10) Send an Email using information in the report.
11) Create a table of contents or an index for your report.
12) Generate bar codes without having to install any fonts

If this sounds interesting you can read my complete comparison including a list of all the functions provided by each DLL. The five UFL providers are:

Bjarke Viksoe (U2lwin32)
Maginus Software (CRUFLMAG)
Millet Software (CUT Light)
Chelsea Tech (File Mgt, Text, Share and others)
CrystalKiwi (Export, Table of Contents)

The only product that has changed since last year is CUT Light, which can now convert numbers to Arabic text and provides more robust encoding for Barcode 128, along with some other enhancements to existing capabilities.

If you need help deploying one of these functions in a project let me know.





Creating a “Distinct Sum” when the duplicates not grouped together

Sunday 24 November 2019 @ 3:36 pm

Crystal has a distinct count function but not a distinct sum. A distinct sum would be a sum that skips values in one field whenever there is a duplicate in a separate “key” field. It would work something like this: “only add each customer’s balance into the total once – even if a customer shows up in several different places in the report. The customer ID would be the “key” field while the balance would be the field you are totaling. It should only count the value on the first instance of the key field.

If you can group the duplicates together the solution is simpler. You can use a running total and set it to “evaluate on change of group” where the group is the key field. I teach this method in my advanced material. But a long ago student showed me a clever way to identify duplicates, even when they were scattered. I had never seen that method and couldn’t find it described anywhere else. I published it in my newsletter in 2004. When I needed to use it last week I decided to post it here.

Last week my challenge was a payroll report that showed employees grouped by department, showing pay and withholding. Pay was split by Dept but the withholding was combined. So when an employee worked in two different departments, his withholding would show up twice in the totals. I needed the totals to count the withholding once per employee, even if the employee showed up in several departments (on different pages).

To use this method you first create a running total field that is a distinct count of the “key” field. Then you create another running total, this time using variables, to total the numeric field. This formula has logic to only add the value when the first running total has changed from the record before. Any time there is a change in the first running total it must mean there is a new value for the “key” field. When the first running total doesn’t change it means that the “key” field value has appeared before. The formula I used looks like this:

WhilePrintingRecords;
NumberVar Prior;
NumberVar LYS;
if {#CustCount} = Prior + 1 //test if first record for this customer
then LYS := LYS + {Customer.Last Year's Sales};
Prior := {#CustCount}; //store current count to use for next record
LYS

If you need a Distinct Sum as a Subtotal you would reset the running total and both of the variables with each group.

I have seen other developers solve this problem by creating an array of all of the “key” values and checking each “key” value against the array before adding the numeric. This method lets Crystal handle that duplicate check so there is no reason to maintain an array.





Converting an Excel column from Characters to Numbers

Sunday 17 November 2019 @ 11:25 pm

I have written before about the challenges of reading data from an Excel, mainly because Excel doesn’t define data types for columns like you do in a data table. That article included a formula to convert a column of numbers into a column of equivalent strings.

Last week I had to do the opposite. A customer wanted to link a data table to a spreadsheet, but the linking field in the spreadsheet had numeric characters, while the data table had a true numeric column. There is nothing you can do in the Crystal linking window to get a numeric column to link to a character column, so we had to convert the Excel column from characters to numbers. Just like the previous article, you can’t fix this by formatting the column. The data type assigned to an Excel column isn’t affected by the format of the column, but only by the actual values stored in that column.

After a few experiments I discovered a solution. If you write a formula like this in Excel:

A1 + 0

The result will be a number even if the cell A1 is a character string with numeric characters. Even better, if there are any true numbers in the column, the formula will work the same for them. So we copied that formula for the entire column and that new column became our linking field.





Correction to “elapsed time string” formula

Saturday 9 November 2019 @ 11:54 pm

My web site has a page for commonly used formulas.  Many have been there for years.  Formula page 9 has two versions of a formula that will convert a number of seconds into an elapsed time string. The long version has days, hours, minutes and seconds.  The shorter version is just hours and minutes.

I was using the short version in a customer’s report and we noticed that the minutes value was sometimes off by one.  After some testing we found that if the remaining seconds were between 30 and 60 the formula would always round down because the formula used a Truncate() function. The Truncate() works correctly in the long version of the formula, because you truncate down to the whole minutes and then display any remaining seconds. But since the shorter version doesn’t display seconds it is more accurate to Round () the seconds to the nearest minute.  So I have updated the short version formula on my site to use the Round () function for minutes.

So those of you who have used that formula should update your reports by changing the last Truncate to a Round, or just taking the updated formula from page 9.





No column headings on the last page (v2.0)

Tuesday 29 October 2019 @ 7:29 pm

Last month I wrote an article about suppressing the page header on the last page when there are no details. This is handy if your last page is a subreport, a chart or a cross-tab. After my newsletter went out one of my readers shared her approach to the same problem. She uses the group header of a dummy group, and sets it to “repeat” on each page.

Any time you have a Group Header you can set it to repeat on each page. One feature of  a repeating GH is that it won’t appear on the last page of a group, unless that page has at least one detail record.  I wrote about that behavior in another article long ago.  So the only trick is to create a primary group that includes every record in the report. Then you set this group header to repeat on each page and it behaves just like a page header, with the exception of not printing on the last page.

So how do you create a group that includes all the records in the report? You group on a value that doesn’t change.  If you have a DB field like “company” that doesn’t change you can use it.  But you can always create a formula that isn’t tied to any data fields.  My favorite dummy group formula is:

WhileReadingRecords;
"All"

The word “All” can be any value. Just keep in mind it will appear as the overall node of the group tree so you might want it to make some sense. The WhileReadingRecords function allows the report to see this static value as a recurring value, which makes it eligible for grouping.

Once you create the formula you use it as Group 1 in the report and then go into Group Options and check “Repeat Group Header on each new page”.  If you put your column headings in this Group Header they will appear on every page, but won’t appear on the last page (unless there are details printing on that page).

And thanks to Tina Nordyke, the DBA for Advocates for Basic Legal Equality, Inc for suggesting this method.





Literal values that include quotes

Saturday 26 October 2019 @ 12:25 am

I was recently working on a formula that had the crystal syntax for “is one of”.  It looked something like this:

{LastName} in [ "Smith","Jones","Thompson","Rutledge","Harris" ]

Each value goes in quotes (single or double). You separate the values with a comma and you put square brackets around the list. So I was surprised today when I saw that the formula was actually like this:

{LastName} in [ "Smith""Jones","Thompson","Rutledge","Harris" ]

Notice the comma missing between the first two values.  The report had been running for months without error messages which I didn’t understand, so I started testing.  My experiments pointed me to a syntax rule that I had read about but never used. It is for when your formula includes a literal string that you surround with double quotes, and when the literal string itself contains double quotes.  Crystal would assume the first quote is the ‘open’ and the second one is the close, even when you want the second one to be part of the visible output.   One solution is to use two consecutive double quotes within the literal. Whenever Crystal finds two consecutive double quotes within a literal surrounded by a pair of double quotes, Crystal will interpret the consecutive quotes as one literal quote and not as a closing quote.  This is much easier to explain with an example.  So if I wanted a formula to output this string:

The syntax for "is one of" uses brackets

I could write it like this inside the Crystal formula:

"The syntax for ""is one of"" uses square brackets"

The formula engine would only display one of the two consecutive double quotes in each pair.  That explains why my formula with the missing comma doesn’t generate an error.  Crystal treated the consecutive double quotes as a single literal and then combined the first two elements in the list as being the single value:

Smith"Jones

There was no error message, but the results would not have been correct.

BTW, the same principle applies to single quotes. If you put two consecutive single quotes in a string surrounded by single quotes, Crystal will ignore the first and treat the second as a literal quote.

The reason I didn’t think of this right away is that I have never used consecutive quotes in a formula. If I have a string that needs to contain single quotes I surround it with double quotes. And if the string needs to contain double quotes I surround it with single quotes. In the rare case that a string needs both I would split it into separate pieces and combine them. I find that using consecutive quote pairs makes the formula harder to follow.





Crystal crashes with no error message

Sunday 13 October 2019 @ 9:09 pm

MDB is the original Microsoft Access database format. It was replaced by the ACCDB format in 2007, but there still applications that use MDB files. For instance I have a handful of customers using Raiser’s Edge software for donor tracking, and this application still creates export files in MDB format.

One Raiser’s Edge customer recently contacted me about a report that kept crashing. There was no error message – Crystal would just shut down. The report had 32 tables and 31 joins. If he deleted one of the tables the report ran fine. As soon as he added the last table the report would crash.

In my testing I found that it didn’t matter which table was dropped. So it became apparent that the issue was a limit, somewhere on the number of tables or joins. But it was hard to determine where the problem lay without any error messages.

First I checked the SQL generated by Crystal Reports and that looked normal. I copied the SQL into a new SQL command but that had the same exact limit.

Next I tried the same report using different connection methods. Both OLEDB and ODBC failed in the same way as DAO.

Then I decided to see if the problem was in the MS Access engine so I copied the SQL From the report and pasted it into a new MS Access query. (I am one of those people who still use MS Access 2002.) The query would run fine in MS Access as long as I dropped one of the tables. If I added that last table the MS Access query would generate an error that said:

“Query is too complex”

I couldn’t find the official limits for MDB files but I did find a page that showed the limits for ACCDB files and it says that the number of tables in a query is limited to 32, which in some cases can be reduced even lower.  So apparently we hit the limit. And worse, when you exceed the limits for MS Access, the report can’t survive to give you an error message.  It just dies.





Next Posts »» «« Previous Posts
Jeff-Net
Recrystallize Pro

Crystal Reports Server