You are on page 1of 79

Crystal Reports® Secrets

X 20 Secret Shortcuts and Workarounds for


Crystal Reports Designers and Developers
This guide is for your personal use, compliments of Business Objects Education Services.
It contains a concise summary of answers to the most common Crystal Reports
questions, along with links to more detailed explanations. Created to help report
designers and developers quickly improve their skills, this guide was:

• Developed by the people who wrote the code – experts who can explain their
secrets, step by step
• Based on the most common questions identified by Technical Support
• Designed to help you get the most out of Crystal Reports. Learn to unlock
the value inside your information to help your organization improve
business performance.
..

ii Business Objects • Crystal Reports Secrets


Contents

Why these secrets are so important


i.) Critical skill deficit ..................................................................................... 5
ii) Cost of inadequate preparation ........................................................... 6
iii) Impact on IT project success .................................................................. 7
iv) Training resources available ................................................................... 8

Top 20 Secrets
Secrets for Report Designers:
#1. How to display every nth record in Crystal Reports ........................ 9
#2. How to display only the report file name on a report ...................11
#3. How to suppress a blank subreport from displaying....................12
#4. How to share subreport data with the main report .......................15
#5. Evaluate null field values in formulas or record selection ..........18
#6. How different 'Keep Together' options affect the report .............23
#7. How to export to PDF or RTF in Crystal Reports............................28
#8. Suppress a section that contains a blank subreport ....................30
#9. How to create a table of contents for a report ...............................39
#10. How to add time fields .........................................................................43
#11. What font types are supported in Crystal Reports? ....................47
#12. How to format specific words or characters within a string ......50
#13. How to display a date range parameter on a report ....................52
#14. How to suppress a blank subreport .................................................54

iii Business Objects • Crystal Reports Secrets


Contents

Secrets for Developers:


#15. How to deploy an application that uses
Crystal Reports and VS .NET...............................................................56
#16. What is Unicows.dll and where can you find it? ..........................59
#17. How to change the data source
using CR for VS .NET application ......................................................60
#18. How to pass Database logon info
to a Crystal Report at runtime in VB .NET .......................................65
#19. How to create a report and add
a parameter field using Report Creation API .................................70
#20. Crystal Reports for Visual Studio .NET............................................76

Summary: ....................................................................................................................78
• More resources available
Worldwide contact information: .........................................................................79

iv Business Objects • Crystal Reports Secrets


Critical Skill Deficit

X Fact: Many users are not adequately prepared

Organizations around the world invest in business intelligence (BI), enterprise resource
planning (ERP) and customer relationship management (CRM) solutions – yet
frequently fail to arm their people with the training they need to get the most out of the
implementation.

According to Meta Group research, three out of every four ERP users raise the white
flag – they do not have the skills they require.

The good news is that the time you invest in learning the secrets presented in this
document and in formal learning will pay off right away – in greater efficiency, boosted
confidence, and better reports.

Overlooked: Let’s learn a lesson from ERP


Three out of four ERP users lack competency

76% user
competency 83%
substandard or didn’t
institute a
failing compre-
hensive
training
42%
plan
no end-user training
beyond that provided at
24% user competency the end of the
satisfactory implementation

Source: Meta Group research, August 2003 as cited in ZD Net online article
“Three out of four ERP users raise the white flag.”

5 Business Objects • Crystal Reports Secrets


Cost of Inadequate Preparation

X Fact: Preparation and skill development are key project success factors

The impact of inadequate preparation may be greater than you think. We all suffer from
the tyranny of the urgent – putting off learning critical skills even though we will
desperately need these very skills in the middle of a demanding project.

Here is the question: What is the cost of failure or delay on your project?

Why do IT Projects fail?

• Incomplete Requirements 13.1%


• Lack of User Involvement 12.4%
• Lack of Resources 10.6%
• Unrealistic Expectations 9.9%
• Lack of Executive Support 9.3%
• Changing Requirements & Specifications 8.7%
• Lack of Planning 8.1%
• Didn’t Need it any longer 7.5%
• Lack of IT Management 6.2%
• Technology Illiteracy 4.3%

Source: Chaos Report N= 365 IT Managers


http://www1.standishgroup.com//sample_research/chaos_1994_2.php

6 Business Objects • Crystal Reports Secrets


Impact on IT project success

X Fact: The real cost of skill deficit is high

Organizations often believe that users are resourceful enough to find their own way
through new programs and systems. While this may be true, an unguided learning
process is much less effective than a systematic approach to training.

Learning the techniques that make a user proficient requires a one-time investment –
whereas failure to master these techniques requires a time investment every time the
user performs a task.

“On average, most individuals spend 50 percent of their time gathering and
collecting the information for standard report analysis and the remaining time
analyzing the information. At those companies where BI tools and technologies have
been implemented in a consistent manner, roughly 20 percent of an individual's time
is spent gathering and collecting, while 80 percent is spent reporting and analyzing
the information for trends, business opportunities, forecasting and other related
value-based analysis”
Hackett Best Practices Strategic Decision Making benchmark, 2002

“68% of IT executives said training of users would improve information access”


Business Week Survey

7 Business Objects • Crystal Reports Secrets


Training Resources Available

X Fact: Continuous learning yields exponential benefit

Once you’ve had a chance to digest these tips and tricks, you’ll probably want to take
your skills to the next level. Trained users take advantage of 20% more product features
– and have both greater competence and higher confidence as a result of their training.

Learn from the experts, the people who created the software. Both classroom and e-
learning training is available.
• Business Objects Education group has trained over 200,000 users.
• Only the creators of the software have in-depth understanding of all of the
software features.
• We employ only the most experienced instructors – professionals with a proven
track record in sharing time-saving tips and best practices.
• 95% of trainees rank their experience as “good” to “excellent” in terms of job
1
relevance.

Courses for Crystal Reports Designers:

• Report Design I: ( http://www.businessobjects.com/training )


Fundamentals of Report Design

• Report Design II: (http://www.businessobjects.com/training)


Business Reporting Solutions

Courses for Crystal Enterprise Administrators:

• Crystal Enterprise: (http://www.businessobjects.com/training)


Administering Users and Content

• Crystal Enterprise: (http://www.businessobjects.com/training)


Administering Servers

• Crystal Enterprise: (http://www.businessobjects.com/training)


Designing and Deploying a Solution

• Crystal Enterprise: (http://www.businessobjects.com/training)


Building and Creating Business Views

1
Source: Analysis of post class evaluations. 2004.

8 Business Objects • Crystal Reports Secrets


#1 How to display every nth record in Crystal Reports

#1 How to display every nth record in Crystal Reports


http://support.businessobjects.com/library/kbase/articles/c2014881.asp

X The information in the article refers to:

Crystal Reports 10
X Applies to:

Reported version and lower


Formulas
Conditional Suppression
Format Section
X Synopsis:

In Crystal Reports (CR), is it possible to display every nth record without indexing the
database table?

For example, you have a report with 100 records but you only want to see every 25th
record. Your report connects to a database table that does not contain an indexed field.
X Solution:

A formula can be created that will display every nth record by conditionally
suppressing all other records. The example below shows how to display every 25th
record.

X Example Formula:

Remainder((recordnumber),25) <> 0

You will employ this formula in the Section Expert.

To apply this formula in the Section Expert:

1. Right-click on the details section and click 'Section Expert'.

2. On the 'Sections' list, click the details section.

3. Leave the check box cleared and click the 'X+2' command button next to 'Suppress
(No Drill-Down)'. The formula editor opens.

9 Business Objects • Crystal Reports Secrets


#1 How to display every nth record in Crystal Reports

4. Type the formula provided by this article.

5. Save your formula and close the formula editor.

6. Click OK in the Section Expert.

You will now only see every 25th record. All other records do not display on the report
because of the conditional suppression at the details level.

X Background Information

This formula returns a value of true for all records not divisible by 25 and a value of false
for all records that are divisible by 25. CR reads the results of the formula to determine if
a record will appear.

X More Information

For more information about the 'Remainder' function or 'Record Number' special
field, refer to the Crystal Reports Online Help by pressing the 'F1' key.

X Training:

Learn more about Crystal Reports - Report Design.

Refer to 'Courses & Schedules' at:

http://www.crystaldecisions.com/training

10 Business Objects • Crystal Reports Secrets


# 2 How to display only the report file name on the report

# 2 How to display only the report file name on the report


http://support.businessobjects.com/library/kbase/articles/c2015683.asp

X The information in the article refers to:

Crystal Reports 10

X Applies to:

All versions
Formulas
Return File Name
X Synopsis

When using the special field called 'filename' the report shows the entire path
including the file name.

How do you display just the report file name on the report?
NOTE: X Solution

The report must be To display just the report file name on a report, use a formula similar to this:
saved before the
formula will return
@ReportFileName:
a value, or it will //This is the formula name
return an empty
string. StringVar Array File:=Split(filename,'\');
NumberVar i := Ubound(File);
This formula is not File[i];
version-specific and
can be placed in any X Training:
report, because it
uses the special
field 'filename', Learn more about Crystal Reports - Report Design.
which exists in
Crystal Reports 8.5, Refer to 'Courses & Schedules' at:
9, and 10.
http://www.crystaldecisions.com/training

11 Business Objects • Crystal Reports Secrets


#3 Suppressing a blank subreport from displaying on the main
report

#3 How to suppress a blank subreport from displaying on the main report

http://support.businessobjects.com/library/kbase/articles/c2000055.asp

X The information in the article refers to:

Seagate Info, Seagate Crystal Reports 5

X Applies to:

Reported version and lower


Hiding subreports that have no records
Using 'Suppress Printing if No Records' checkbox
X Synopsis

NOTE: How can you suppress a blank subreport from displaying on the main report.
Moreover, you want to suppress the sections within a subreport, if there is no data, so
New to Crystal that it does not display on the main report?
Reports 9 is the
'Suppress Blank
Subreport' check
box. For more X For example:
information on how
There is a subreport contained in the main report. If the subreport does not contain any
to suppress blank
data, you do not want it to display in the main report. You want to suppress the sections
subreports in CR 9,
of the blank subreport.
refer to our
knowledge base
article c2011893.
X Solution

A subreport is an object within the Crystal Reports designer. Since the subreport is
NOTE:
inserted into the main report, it cannot be entirely suppressed.
This workaround
Even when a subreport does not have any records, the subreport object still exists
applies to Crystal
within a section of the main report. This means the Crystal Reports designer does not
Reports 8.5 and
consider a section that contains a subreport as a blank section.
earlier.
You notice that by selecting the 'Suppress if blank' option, from the 'Section Expert'
does not work.

To workaround this, you must first suppress the blank subreport, then shrink the blank
section.

12 Business Objects • Crystal Reports Secrets


#3 Suppressing a blank subreport from displaying on the main
report

X Suppressing a Blank Subreport


NOTE:
To suppress the blank subreport, complete the following:
This only
suppresses the 1. In the main report, right-click the subreport object and click 'Edit Subreport'. This
subreport from takes you to the 'Subreport' tab of the main report.
printing, so you
will not see the 2. On the 'File' menu, click 'Report Options'.
contents of the
subreport; the 3. Select the 'Suppress Printing if No Records' checkbox, and then click 'OK'.
subreport still
exists as an object 4. Return to the 'Preview' tab of the main report.
in the main report.
This means you 5. Refresh the report.
still cannot format
the main report Blank subreports now appear as empty boxes on the report.
section that
contains the blank
X Shrinking a Blank Section

To shrink the blank section, complete the following:

1. Format the subreport object so there are no borders:

· on the main report, right-click the subreport object and click 'Format Subreport'.

· on the 'Borders' tab, select 'None' from the Top, Bottom, Right and Left boxes.

· Click 'OK' to return to the report.

2. In 'Design' tab of the main report, resize the height of the subreport object so it is as
short as possible.

3. Move the subreport object so it is at the very top of the section.

4. On the 'Format' menu of the main report, click 'Section'.

5. Select the section containing the subreport, select the 'Fit Section' checkbox, and then
click 'OK' to return to the report.

13 Business Objects • Crystal Reports Secrets


#3 Suppressing a blank subreport from displaying on the main
report

Now when you preview the main report, the blank subreports are hidden from view.

CAUTION:

If you want to actually suppress the section in the main report that contains the blank
subreport, instead of merely concealing the blank subreport on the main report, refer to
knowledge base article c2005853.

Keep in mind, however, that the solution in knowledge base article c2005853 requires
inserting another subreport, which will significantly increase the time it takes to process and
display your report.

X Training:

Learn more about Crystal Reports - Report Design.

Refer to 'Courses & Schedules' at:

http://www.crystaldecisions.com/training

14 Business Objects • Crystal Reports Secrets


#4 How to Share Subreport Data with the Main Report

#4 How to Share Subreport Data with the Main Report


http://support.businessobjects.com/library/kbase/articles/c2007600.asp
X The information in the article refers to:

Seagate Info, Crystal Reports 7


X Applies to:

Reported version and higher


Shared variables
Passing data between subreport and main report
X Synopsis

A report contains a subreport. Data from the subreport is required for calculations in
the main report.

How can you share subreport data with the main report in version 7 (or higher) of the
Crystal Reports Designer?
X Solution

Shared variables, introduced in Crystal Reports version 7, make it easier to pass values
NOTE: from a subreport to the main report. Using shared variables requires two formulas: one
to store the value in a shared variable, the other to retrieve the value from the shared
This is not possible variable.
with On Demand
Subreports in The most important thing to remember when using shared variables is that Crystal
Crystal Reports. Reports must first evaluate the formula where the value is stored before evaluating the
formula that retrieves the shared variable.

For example if you want to pass a grand total from the subreport to do a calculation in
the main report, follow these steps:

1. In the subreport, create a formula similar to the one below:

//@SubFormula
//Stores the grand total of the
//{Orders.Order Amount} field
//in a currency variable called 'myTotal'

15 Business Objects • Crystal Reports Secrets


#4 How to Share Subreport Data with the Main Report

WhilePrintingRecords;
Shared CurrencyVar myTotal := Sum ({Orders.Order Amount})

2. Place this formula in your subreport.

3. In the main report, create a formula that declares the same variable name:

//@MainFormula
//Returns the value that was stored
//in the shared currency variable called
//myTotal in the subreport

WhilePrintingRecords;
Shared CurrencyVar myTotal;
myTotal

4. Place @MainFormula in a main report section that is beneath the section containing
the subreport.

For the shared variable to return the correct value in the main report, you must place
@MainFormula in a main report section that is beneath the section containing the
subreport. This ensures Crystal Reports evaluates the @SubFormula before
@MainFormula.

One way to do this is to insert a section below the section containing the subreport, and
place @MainFormula in this new sub-section:

· On the 'Format' menu, click 'Section'.

· On the 'Sections' list, click the section containing the subreport.

· Click 'Insert' (at top of dialog box). This inserts an additional subsection.

· Click 'OK' to return to the report, and insert @MainFormula into this new sub-
section.

The next time you preview the report, @MainFormula displays the value from the
subreport. In this particular example, that value was the grand total of the
{Orders.Order Amount} field.

16 Business Objects • Crystal Reports Secrets


#4 How to Share Subreport Data with the Main Report

5. Once you have verified that @MainFormula is returning the correct value from the
subreport, you can include this formula in other main report formulas, such as:

//@NewFormula
//includes data from subreport

{@MainFormula}+ Sum ({Customer.Last Year's Sales})

Place this formula in the same section as @MainFormula, or in a section further down
on the report.

You have now successfully shared data from a subreport with the main report.

X Training

Learn more about subreports in the


Crystal Reports - Report Design III training course.

Refer to 'Courses & Schedules' at:

http://www.businessobjects.com/training

17 Business Objects • Crystal Reports Secrets


#5 How to evaluate null field values in formulas or record
selection criteria

#5 How to evaluate null field values in formulas or record selection


criteria
http://support.businessobjects.com/library/kbase/articles/c2010914.asp

X The information in the article refers to:

Crystal Reports 9
X Applies to:

All versions
Record selection criteria
Formula displays unexpected results
IsNull function
X Synopsis

A database field contains values and null values. In Crystal Reports (CR), when
previewing the report, a list of values and blank values appears in the Details section.

How can you evaluate this database field in formulas or record selection criteria to
return the expected result set?
X Example Scenario

1. Add a Number field, {YourDatabaseTable.NumberField}, to the Details section of the


report.

Field values contained in the database


1
<Null>
<Null>
2
NOTE: 3
The <blank space> in Field values that appear in CR
CR represents the 1
null values from the <blank space>
database field. <blank space>
2
3

18 Business Objects • Crystal Reports Secrets


#5 How to evaluate null field values in formulas or record
selection criteria

2. Add the following record selection criteria to the report:

{YourDatabaseTable.NumberField} < 3

3. Upon adding the record selection criteria, the values that appear on the report are not
what you expected.

Expected field values based on record selection criteria


1
<blank space>
<blank space>
2

Field values that appear in CR based on the record selection criteria


1
2

Why do the null values not appear in the result set based on the record selection criteria?

How can you evaluate the null values in the Number field to return the expected result
set?

Why do blank values or incorrect values appear in the result set of a formula?

X Solution

The expected result set does not appear because the example of record selection criteria
does not evaluate the null values. Null values in the Number field are not evaluated as
zero (0) values by default.

In CR, to evaluate fields that contain null values to return the expected result set, use one
of the following solutions:

Option A) Convert the null value to the default value of their data type.

EXAMPLE DEFAULT VALUES BY DATA TYPE

* The null values in a Number field are converted to a zero (0) number value.

* The null values in a String (Text) field are converted to an empty string ("") value.

19 Business Objects • Crystal Reports Secrets


#5 How to evaluate null field values in formulas or record
selection criteria

* The null values in a Date field are converted to zero (0, 0, 0) date values.

* The null values in a Date-time field are converted to zero (0, 0, 0, 0, 0, 0) date-time
values.

- OR -

Option B) Evaluate the null value within record selection criteria or within
formulas using the IsNull function.

Follow the steps below for A) or B) to evaluate null values to return the expected result
set.

Also, with regards to the related issue, blank values or incorrect values appear because
the formula includes a database field that contains null values. Follow the steps below
for A) or B) to correctly evaluate the null values to return the expected result set.

A) STEPS TO CONVERT NULL FIELD VALUES TO DEFAULT VALUE FOR ALL


FIELDS IN CR

1. Click File > Report Options

2. Select the 'Convert NULL Field Values to Default' check box.

NOTE: 3. Click 'OK'.

The IsNull Selecting 'Convert NULL Field Values to Default' affects all database fields on the
function report. CR is now able to successfully evaluate any null or blank values contained in
evaluates the the database fields according to the default value of their data type.
database field(s)
for null values.
B) STEPS TO EVALUATE THE NULL FIELD VALUES IN CR
It is important to
1. Create formula or record selection criteria.
evaluate every
database field
2. Use the IsNull function at the beginning of the formula or record selection criteria.
included in the
formula or record
3. If applicable, specify a value or action if the IsNull function evaluates a null record.
selection criteria
for null values.

20 Business Objects • Crystal Reports Secrets


#5 How to evaluate null field values in formulas or record
selection criteria

EXAMPLES OF THE ISNULL FUNCTION IN A FORMULA OR RECORD


SELECTION CRITERIA

Evaluate for null values in a Date field

//Date values that are not null are returned based on this record selection criteria. //Also, date
values are returned where it is less than the current date.
Not IsNull({YourDatabaseTable.DateField})
And {YourDatabaseTable.Datefield} < CurrentDate;

b) Evaluate for null values in a Number field to create a total

//This formula evaluates if the Number field contains null records. If the record contains a //null
value, the total is increased by a zero value. If the record is not null, the total is //increased by the
value of the record.

Whileprintingrecords;
Numbervar Total;
If IsNull({YourDatabaseTable.NumberField})
Then Total := Total
Else Total := Total + {YourDatabaseTable.NumberField};

c) Evaluate for null values in a String or Text field

//This formula evaluates if the String field contains null records. Additionally, the Trim
//formula function is used to account for a blank space caused by pressing the Space Bar.

WhilePrintingRecords;
Stringvar Message;
If IsNull({YourDatabaseTable.StringField}) or Trim({YourDatabaseTable.StringField}) = ""
Then Message := "Your Message"
Else Message := {YourDatabaseTable.StringField}

Upon completing the above steps, CR will successfully evaluate null field values in a
formula or record selection criteria to return the expected result set.

X Background information

If the 'Convert Null Field Values to Default' check box is not selected or if the database
field has not been evaluated using the IsNull function, the following behavior occurs in
CR when a null value is encountered:

* Formulas or record selection criteria stop evaluating the null value. For example, if the

21 Business Objects • Crystal Reports Secrets


#5 How to evaluate null field values in formulas or record
selection criteria

formula is incrementing a value based on the database field, the value does not
increment nor does the remainder of the formula continue to evaluate. However, the
formula continues on to evaluate the next record.

* Formulas or record selection criteria return a blank value. If the formula's calculations
are based on the field values, it is possible to return incorrect values.

X Training:

Learn more about additional functions in the


Crystal Reports - Report Design II training course.

Refer to 'Courses & Schedules' at:

http://www.crystaldecisions.com/education

22 Business Objects • Crystal Reports Secrets


#6 How Different 'Keep Together' Options Affect the Report

#6 How Different 'Keep Together' Options Affect the Report


http://support.businessobjects.com/library/kbase/articles/c2010715.asp

X The information in the article refers to:

Seagate Info, Crystal Reports 8.5


X Applies to:

Reported version and lower


Keep Group Together
Keep Columns Together
Keep Object Together
X Synopsis

In the Crystal Reports (CR) Designer, how do the different 'Keep Together' options
affect the report?

The 'Keep Together' options in CR are as follows:

* Keep Together
* Keep Group Together
* Keep Object Together
* Keep Columns Together

Where do you find the 'Keep Together' options in CR and how do they affect your
report?
X Solution

The 'Keep Together' options are available to format objects and sections of the report.
The 'Keep Together' options affect how the report displays the particular object or
section.

Based on the report sections and commonly used report objects, this article provides
the following:

* Where to find the 'Keep Together' options


* Example report details
* How the report is affected based on the example report details

Report sections and commonly used report objects that include the 'Keep Together'

23 Business Objects • Crystal Reports Secrets


#6 How Different 'Keep Together' Options Affect the Report

options:

A) Report Header/Report Footer, Group Header/Group Footer, Details

B) Group Options

C) Subreports, Text Objects, Ole Objects, And Other Database Fields

D) Cross-tabs

A) REPORT HEADER/REPORT FOOTER, GROUP HEADER/GROUP


FOOTER, DETAILS

To locate the 'Keep Together' option for the different sections of the report, follow these
steps:

1. Click Format > Section.

2. In the Section Expert, select the section.


NOTE:
'Keep Together' is 3. Under the Common tab, select 'Keep Together' check box.
unavailable for the
Page Header and When the 'Keep Together' option is selected, CR keeps the entire instance of the
Page Footer particular section on the same page.
sections. This is by
design. Each Page EXAMPLE REPORT DETAILS:
Header and Page
Footer is already * The Group Footer is three inches in height.
designed to keep * The 'Keep Together' option is selected for the Group Footer section.
together at the top * There is only one inch available at the end of the page.
and bottom of each
page. Based on the EXAMPLE REPORT DETAILS, the entire Group Footer section will begin
at the top of the next page.
NOTE:
Do not use this
option if your
intention is to keep
the entire group
together. Use the
'Keep Group
Together' option as
described in B)

24 Business Objects • Crystal Reports Secrets


#6 How Different 'Keep Together' Options Affect the Report

B) GROUP OPTIONS

To locate the 'Keep Group Together' option for inserting or changing a group, follow
these steps:
NOTE:
1. Click the following options depending on whether you are inserting a new group or
If the group changing an existing group:
instance spans
multiple pages, * Insert > Group for inserting a new group
'Keep Group * Report > Change Group Expert > Options for changing an existing group
Together' option
starts on a new 2. Under the "Group Options" heading, select the 'Keep Group Together' check box.
page and continues
through the 3. Click 'OK'.
multiple pages
until the particular EXAMPLE REPORT DETAILS:
group instance is
completed. * The Group Header, Details and Group Footer are displayed for each group instance.
* The amount of space required to display for a group instance exceeds the remaining
If more than one space available on the report page.
group instance can
fit on one page, Based on the EXAMPLE REPORT DETAILS, the entire group instance will start on a new
more than one page. The entire group instance includes the Group Header, Details and Group Footer.
group instance will
display on the same
page. C) SUBREPORTS, TEXT OBJECTS, OLE OBJECTS, AND OTHER DATABASE
FIELDS
Do not use this
option if the To locate the 'Keep Object Together' option for formatting subreports, text objects, OLE
intended purpose is objects, and other database fields, follow these steps:
to have each group
start on a new page. 1. Right-click the report object.
If the intended
purpose is to have 2. Select the one of following available options depending on the object type:
each group start on
* 'Format Subreport' for subreports
* 'Format Text' for text objects
* 'Format Graphic' for OLE objects
* 'Format Field' for database fields

25 Business Objects • Crystal Reports Secrets


#6 How Different 'Keep Together' Options Affect the Report

3. Under the Common tab, select the 'Keep Object Together' check box.

When the 'Keep Object Together' option is selected, CR keeps the entire instance of the
particular object on the same page.

EXAMPLE REPORT DETAILS:

· The Group Footer contains a subreport and a text object.


· The Group Footer contains a subreport and a text object.
· The text object is placed above the subreport.
· The subreport in the Group Footer instance exceeds the remaining ·mount of space
available on that page.
· The Group Footer section is not formatted with the 'Keep Together' option.
· The Group is not formatted with the 'Keep Group Together' option.
· The text object is not formatted with the 'Keep Object Together' option.
· The subreport is formatted with the 'Keep Object Together' option.

Based on the EXAMPLE REPORT DETAILS, the subreport will start on a new page.
However, the Group Footer instance and the text object will start on the previous page.
The 'Keep Object Together' option is only applicable to the particular object.

D) CROSS-TABS:
To locate the 'Keep Columns Together' option for formatting a cross-tab, follow these
steps:

1. Right-click the cross-tab.

2. Select 'Format Cross-tab'.

3. Under the Customize Style tab, select the 'Keep Columns Together' check box.

When the 'Keep Columns Together' option is selected, CR keeps the columns together if
a column width spans across to a second page.

EXAMPLE REPORT DETAILS:


· The Report Footer contains a cross-tab.
· The cross-tab columns span multiple pages.

Based on the EXAMPLE REPORT DETAILS, the 'Keep Columns Together' option is

26 Business Objects • Crystal Reports Secrets


#6 How Different 'Keep Together' Options Affect the Report

selected, the columns that would span across the edge of the pages start on a new page.
A cross-tab column is not divided between two pages.

X Training

Learn more about object and section formatting


options in these courses:

· Crystal Reports - Report Design I

· Crystal Reports - Report Design II

Refer to 'Courses & Schedules' at:

http://www.businessobjects.com/training

27 Business Objects • Crystal Reports Secrets


#7 Exporting to PDF or RTF in Crystal Reports

#7 Exporting to PDF or RTF in Crystal Reports


http://support.businessobjects.com/library/kbase/articles/c2006248.asp

X The information in the article refers to:

Crystal Reports 9
X Applies to:

Reported version and lower


Report Design
Exporting to PDF and RTF
X Synopsis

Can I export my report to Adobe Acrobat PDF (Portable Document Format) or RTF
(Rich Text Format) from the Crystal Reports report designer? If so, how?
X Solution

Crystal Reports 8.5 and later allows exporting to PDF. Exporting to PDF in Crystal
Reports 8 and earlier is not supported. Crystal Reports 8 and later allows exporting to
RTF.

Exporting to PDF or RTF in Crystal Reports 8.5 retains the best WYSIWYG (What-you-
see-is-what-you-get) format of the original report.

Exporting to PDF and RTF in Crystal Reports 8.5 support many features that other
exporting formats cannot.
X Export to PDF
NOTE: X 1. On the 'File' menu, click 'Export'.
This export DLL is 2. In the 'Export' dialog box, click 'Acrobat Format (PDF)' from the 'Format' drop-down
designed to work box.
with Adobe Acrobat
3. Click the destination of your choice from the 'Destination' drop-down box. (To save to
a file on your computer, click 'Disk file'.)

4. Click 'OK'.

28 Business Objects • Crystal Reports Secrets


#7 Exporting to PDF or RTF in Crystal Reports

X Export to RTF

1. On the 'File' menu, click 'Export'.

2. In the 'Export' dialog box, click 'Rich Text Format' from the 'Format' drop-down box.

3. Click the destination of your choice from the 'Destination' drop-down box. (To save to
a file on your computer, click 'Disk file'.)

4. Click 'OK'.

X More Information

For information on troubleshooting errors exporting to PDF and RTF refer to our
knowledge base article c2012282.

For information on ALL the formats that Crystal Reports has exporting functionality to,
download the applicable document.

· For Crystal Reports version 7 - SCR7ExportLimitations.zip

· For Crystal Reports version 8 - SCR8_ExportLimitations.zip

· For Crystal Reports version 8.5 - cr85_exportlimitations.zip

· For Crystal Reports version 9 - cr9_exportlimitations.pdf

These documents also list all supported and unsupported exporting features in Crystal
Reports 7, 8, and 8.5.

These information sources are available on our website:


http://support.businessobjects.com/search

X Training

Learn more about exporting in the Crystal Reports - Report Design I training course.

Refer to 'Courses & Schedules' at


http://www.businessobjects.com/training

29 Business Objects • Crystal Reports Secrets


#8 Suppress a section that contains a blank subreport

#8 Suppress a section that contains a blank subreport


http://support.businessobjects.com/library/kbase/articles/c2005853.asp

X The information in the article refers to:

Seagate Info, Seagate Crystal Reports 8.5


X Applies to:

Reported version and lower


Seagate Info
Blank Subreports
Conditional Suppression
X Synopsis

In Crystal Reports (CR) 8.5 and earlier, how do you suppress a section in the main
report that contains a blank subreport?

For example:
A subreport is placed in the group header of the main report.

You notice that if the subreport does not return data the group header contains a blank
space the size of the subreport. You want to suppress the group header of the main
report when the subreport is blank.

X Solution
NOTE:
The group header that contains the blank subreport does not shrink because the
subreport is an object within the Crystal Reports designer. A section containing a
New to Crystal
subreport is never blank even if the subreport is because it contains a subreport object.
Reports 9 is the
'Suppress Blank
You notice that by selecting the 'Suppress if blank' option, from the 'Section Expert'
Subreport' check
does not work.
box. For more
information on
This knowledge base article provides a solution to suppress a section that contains a
how to suppress
blank subreport for CR 6, 7, 8 and 8.5. The following procedures must be completed in
blank subreports
order to achieve the desired results:
in CR 9, refer to
our knowledge
· creating a duplicate subreport
base article
c2011893.
· placement of a duplicate subreport

30 Business Objects • Crystal Reports Secrets


#8 Suppress a section that contains a blank subreport

· creating a formula to test if the subreport is blank

· conditionally suppressing a section that contains original subreport

· minimizing a duplicate subreport and resizing the section

NOTE: X Crystal Reports 7, 8 and 8.5

You must create To suppress a section that contains a blank subreport in CR 7, 8 and 8.5, complete the
another subreport following:
based on the original
subreport. To create X Creating a Duplicate Subreport
a duplicate
subreport, complete Place the duplicate subreport into the section above the original subreport. For example,
the following steps: if the original subreport is contained in the group header of the main report, create
1. From the main another group header and place the duplicate subreport into it.
report in CR, right-
click the subreport. To insert a section into the report, complete the following steps:
2. From the fly-out
menu, select 'Save 1. In design mode, right-click the left gray margin where the subreport is located.
Subreport As'.
3. Provide a name for For example, if the subreport is located in the group header, right-click the left gray
the duplicate margin at the group header level.
subreport and click
'Save'. 2. From the fly-out menu, select 'Insert Section Below'. You notice another section is
Placement of a inserted into the report labeled 'b'.
Duplicate Subreport
For example, by inserting another group header you notice that there is group header A
and group header B.

3. Select the original subreport, drag and drop it into the second section.

4. Insert the duplicate subreport by selecting 'Subreport', from the 'Insert' menu.

5. Select 'Choose a report', from the 'Insert Subreport' dialog box.

6. Browse to find the duplicate subreport.

7. Select the report and click 'Open'.

31 Business Objects • Crystal Reports Secrets


#8 Suppress a section that contains a blank subreport

8. Click 'OK'. The duplicate subreport will be attached to the cursor.

9. Insert the subreport in the new section (such as group header b from step 2).

10. In the main report, on the 'Edit' menu click 'Subreport Links'. The top drop-down box
will contain both the original and duplicate subreports. Compare these two subreports
and enure that the fields in the 'Filed(s) to link to' box are the same. Also, check that the
parameter in the bottom-left drop-down box and the field in the bottom-right drop-
down box are the same.

X Creating A Formula To Test If The Subreport Is Blank

In the duplicate subreport, you must create a formula to test whether the contents of the
subreport are blank. The results of this formula are going to be stored as a shared
variable and shared with the main report.

To create this formula, complete the following steps:

1. Right-click on the duplicate subreport and from the fly-out menu, select 'Edit
Subreport'.

2. From the 'Insert' menu, select ' select 'Field Object'. This launches the 'Field Explorer'.

3. Select 'Formula Fields' and select the 'New' icon.

4. Type a name into the 'Formula Name' box and click 'OK'. For example, CheckForNull.
This launches the formula editor.

5. Create a formula similar to the following:

// @CheckForNull
Whileprintingrecords;
Shared BooleanVar Suppress;
If IsNull(Count({Table.field})) or Count(Table.field) = 0 then Suppress:= TRUE
Else Suppress:= FALSE

6. Place @CheckForNull in the Report Header of the duplicate subreport.

32 Business Objects • Crystal Reports Secrets


#8 Suppress a section that contains a blank subreport

X Conditionally Suppressing a Section Containing Original Subreport

To conditionally suppress the section that contains the original subreport, complete the
following steps:

1. From the 'Format' menu, select 'Section'. This launches the 'Section Expert'.

2. From the 'Section Expert' dialog box, select the section that contains the original
subreport.

3. Click the 'X+2' button beside the 'Suppress (No drill down) check box. Ensure the
checkbox is clear.

4. In the 'Format Formula Editor', create a formula similar to the following:

// The section will be suppressed if


// variable Suppress is True
Whileprintingrecords;
Shared BooleanVar Suppress = True

Now when you preview the report, you notice that the sections that contain a blank
subreport are suppressed. However, the section that contains the duplicate subreport is
visible on the main report. In order to suppress the section still visible you must
minimize and resize the section.

X Minimizing the Duplicate Subreport & Resizing the Section

To minimizing the duplicate subreport on the main report and resize the section,
complete the following steps:

1. From the main report, right-click the duplicate subreport.

2. From the fly-out menu, select 'Edit subreport'.

3. Suppress all of the sections in the duplicate report.

4. Select the main report.

5. Right-click the duplicate subreport, and from the fly-out menu, select 'Format
Subreport'.

6. From the 'Format Editor', select the 'Border' tab.

33 Business Objects • Crystal Reports Secrets


#8 Suppress a section that contains a blank subreport

7. From 'Line style', select 'None' for Left, Right, Top, Bottom.

8. Select the main report.

9. Resize the section that contains the duplicate subreport to be as small as possible.

X Crystal Reports 6

Before you begin this process, you will need to download uflstore.zip from our website
at:

http://support.crystaldecisions.com/downloads

The reason you need to obtain this file is because shared variables were introduced in
Crystal Reports 7. In order to suppress a section that contains a blank subreport in
Crystal Reports 6, you will need to use the store and fetch function.

To suppress a section that contains a blank subreport in Crystal Reports 6, complete the
following:

X Creating a Duplicate Subreport

You must create another subreport based on the original subreport. To create a duplicate
subreport, complete the following steps:

1. From the main report in CR, right-click the subreport.

2. From the fly-out menu, select 'Save Subreport As'.

3. Provide a name for the duplicate subreport and click 'Save'.

X Placement of a Duplicate Subreport

Place the duplicate subreport into the section above the original subreport. For example,
if the original subreport is contained in the group header the main report, create another
group header and place the duplicate subreport into it.

To insert a section into the report, complete the following steps:

1. In design mode, right-click the left gray margin where the subreport is located.

34 Business Objects • Crystal Reports Secrets


#8 Suppress a section that contains a blank subreport

For example, f the subreport is located in the group header, right-click the left gray
margin at the group header level.

2. From the fly-out menu, select 'Insert Section Below'. You notice another section is
inserted into the report labeled 'b'.

For example, by inserting another group header you notice that there is group header A
and group header B.

3. Select the original subreport, drag and drop it into the second section.

4. Insert the duplicate subreport by selecting 'Subreport', from the 'Insert' menu.

5. Select 'Choose a report', from the 'Insert Subreport' dialog box.

6. Browse to find the duplicate subreport.

7. Select the report and click 'Open'.

8. Click 'OK'. The duplicate subreport will be attached to the cursor.

9. Insert the subreport in the new section (such as group header b from step 2).

10. In the main report, on the 'Edit' menu click 'Subreport Links'. The top drop-down box
will contain both the original and duplicate subreports. Compare these two subreports
and enure that the fields in the 'Filed(s) to link to' box are the same. Also, check that the
parameter in the bottom-left drop-down box and the field in the bottom-right drop-
down box are the same.

X Creating a Formula to Test if the Subreport is Blank

In the duplicate subreport, you must create a formula to test whether the contents of the
subreport are blank. The results of this formula are going to be stored as a shared
variable and shared with the main report.

To create this formula, complete the following steps:

1. Right-click on the duplicate subreport and from the fly-out menu, select 'Edit
Subreport'.

2. From the 'Insert' menu, select ' select 'Field Object'. This launches the 'Field Explorer'.

35 Business Objects • Crystal Reports Secrets


#8 Suppress a section that contains a blank subreport

3. Select 'Formula Fields' and select the 'New' icon.

4. Type a name into the 'Formula Name' box and click 'OK'. For example, CheckForNull.
This launches the formula editor.

5. Create a formula similar to the following:

// @CheckForNull
Whileprintingrecords;
If IsNull(Count(Table.field)) or Count(Table.field) = 0 then
StoreBooleanVar ("Suppress", True)
else StoreBooleanVar("Suppress", False)

6. Place @CheckForNull in the Report Header of the duplicate subreport.

X Conditionally Suppressing a Section Containing Original Subreport

To conditionally suppress the section that contains the original subreport, complete the
following steps:

1. From the 'Format' menu, select 'Section'. This launches the 'Section Expert'.

2. From the 'Section Expert' dialog box, select the section that contains the original
subreport.

3. Click the 'X+2' button beside the 'Suppress (No drill down) check box. Ensure the
checkbox is clear.

4. In the 'Format Formula Editor', create a formula similar to the following:

// Conditional suppression on section containing original subreport


Whileprintingrecords;
FetchBooleanVar("Suppress") = True

Now when you preview the report, you notice that the sections that contain a blank
subreport are suppressed. However, the section that contains the duplicate subreport is
visible on the main report. In order to suppress the section still visible you must
minimize and resize the section.

36 Business Objects • Crystal Reports Secrets


#8 Suppress a section that contains a blank subreport

X Minimizing the Duplicate Subreport & Resizing the Section

To minimize the duplicate subreport on the main report and resize the section,
complete the following steps:

1. From the main report, right-click the duplicate subreport.

2. From the fly-out menu, select 'Edit subreport'.

3. Suppress all of the sections in the duplicate report.

4. Select the main report.

5. Right-click the duplicate subreport, and from the fly-out menu, select 'Format
Subreport'.

6. From the 'Format Editor', select the 'Border' tab.

7. From 'Line style', select 'None' for Left, Right, Top, Bottom.

8. Select the main report.

9. Resize the section that contains the duplicate.

TIP:

To distinguish between the section containing the duplicate subreport and the section
containing the original subreport, you can format one of the sections with a different
background color.

To format a section with a background color, follow these steps:

1. Right click the section to select it and from the fly out menu select 'Format Section'.

2. In the 'Section Expert' select the section containing the duplicate subreport from the
'Sections' dialog box.

3. Click the 'Color' tab and select the 'Background Color' check box.

4. Select the desired color from the list.

37 Business Objects • Crystal Reports Secrets


#8 Suppress a section that contains a blank subreport

X Training:

Learn more about subreports in the


Crystal Reports - Report Design III training course.

Refer to 'Courses & Schedules' at:

http://www.crystaldecisions.com/training

38 Business Objects • Crystal Reports Secrets


#9 How to create a table of contents for a report

#9 How to create a table of contents for a report


http://support.businessobjects.com/library/kbase/articles/c2011950.asp

X The information in the article refers to:

Crystal Reports 9
X Applies to:

Reported version only


Table of Contents
Subreports
Add Command
X Synopsis

In Crystal Reports (CR) 9, is it possible to create a table of contents at the beginning of


a report?

A table of contents would be in the Report Header, showing group names next to the
page numbers the groups start on.
X Solution

You can make a table of contents using a subreport with a command object.

Using a command object it is possible to write to a database from CR. The following
example will use a subreport to write group names and page numbers to a new table in
your database.

WARNING:

Crystal Reports is not recommended as a tool to write to, update or delete from a
database. Database clients or applications designed specifically to edit databases should
be used instead. However, now that CR has full SQL functionality it is possible to write
to, update and delete from databases. This article is provided as a tip.

Before attempting to implement the steps in this article, consult your Database
Administrator (DBA). Your DBA needs to grant specific rights to your database.

39 Business Objects • Crystal Reports Secrets


#9 How to create a table of contents for a report

X Create a Table of Contents

1. Create a new table in your database called TableOfContents. Create three fields in this
table:

· Grouper (String data type)(Ensure this field is at least as large as your longest group
field value)

· Page (Number data type) · DateTime (DateTime data type)

2. Assign rights to write to, delete, and update this table to any users of this report. The
TableOfContents table will be updated as the report changes.

WARNING:

Use INSERT INTO, DELETE or UPDATE statements at your own risk. Once a
command object containing an INSERT INTO, DELETE or UPDATE statement has
run, the database has changed and the changes may not be reversible.

3. On a grouped report (for this example the report is grouped on the ProductName
field), in the 'Insert' menu, click 'Subreport'. Name this subreport 'Table Of Contents'.
Connect this subreport to the new TableOfContents table and insert the
TableOfContents.Grouper and TableOfContents.Page fields in the Details section.
Sort this subreport by the TableOfContents.Page field.

4. Insert the 'Table of Contents' subreport in the Report Header section.

5. Right-click the gray area to the left of the Report Footer, and then click 'Insert Section
Below'. There will now be 'Report Footer a' (RFa) and 'Report Footer b' (RFb).

6. In the Main report, on the 'Insert' menu, click 'Subreport'. Name this subreport
'UpdateTOC'. In the 'Database Expert' dialog box, browse to your Table of Contents data
source, then double-click 'Add Command'. The 'Add Command to Report' dialog
box will appear.

7. Click the 'Create' button to create a parameter. Name the parameter 'LinkReceiver' and
click 'String' from the 'Value Type' drop-down box. Create another parameter named
'DateTime' with a 'DateTime' value type.

40 Business Objects • Crystal Reports Secrets


#9 How to create a table of contents for a report

NOTE: 8. In the 'Add Command to Report' dialog box enter a SQL Query similar to the
following:
This SQL Query (and
any other SQL syntax {?LinkReceiver}
in this article) is DELETE FROM "TableOfContents"
written for a WHERE "TableOfContents"."DateTime" <> {?DateTime};
Microsoft SQL Server SELECT * FROM "TableOfContents"
database. Consult the
database manual or This command object will add new GroupName and PageNumber data to the
Database TableOfContents table and delete any existing data based on the ?DateTime
Administrator for the parameter.
correct syntax for
your data source. 9. Insert the Grouper and the Page fields in the subreport Details section. Suppress all of
the subreport sections.
Business Objects
Technical Support 10. Insert the 'UpdateTOC' subreport in the Report Footer B (RFb) section. (This is to
does not provide ensure that the formula used to link the subreport is processed before the subreport is
support for writing processed.)
SQL queries, as they
are database specific. 11. Right-click the 'UpdateTOC' subreport, and then click 'Format Subreport'. Click the
'Border' tab, and then click 'None' from the 'Left', 'Right', 'Top' and 'Bottom' drop-down
boxes. Click 'OK' to close the 'Format Editor' dialog box.

12. In the main report, create a formula named 'DateTime' with the following syntax:
CurrentDateTime

NOTE:
13. Insert this formula in the main report's Report Header section.
The output of this
formula will look 14. Create another formula named 'LinkMaker' with the following syntax and place it in
similar to the Group Header section of the main report:
this:
INSERT INTO
WhilePrintingRecords;
TableOfContents VALUES StringVar link;
('Bikes',1,'2003-04-04 If Not InRepeatedGroupHeader Then
12:32:01') link := link &
INSERT INTO
TableOfContents VALUES
"INSERT INTO TableOfContents VALUES ('" &
('Locks',2,'2003-04-04 GroupName ({Product.Product Name}) & "'," &
12:32:01') ToText(PageNumber,0) & ",'" &
ToText({@DateTime}, "yyyy-MM-dd HH:mm:ss") &
"')" & chr(10);
link

41 Business Objects • Crystal Reports Secrets


#9 How to create a table of contents for a report

15. Create another formula named 'LinkPasser' with the following syntax and place it in
the Report Footer A (RFa) Section of the main report:

WhilePrintingRecords;
StringVar link;
link

16. In the main report, in the 'Edit' menu, click 'Subreport Links'. In the 'Subreport Links'
dialog box click the 'UpdateTOC' subreport from the 'For subreport' drop-down box.

17. Click the '@DateTime' Formula field from the 'Available Fields' box and move it to
the 'Field(s) to link to' box. In the 'Subreport parameter field to use' drop-down box, click
the '?DateTime' parameter.

18. Repeat step 15, connecting the '@LinkPasser' Formula field to the '?LinkReceiver'
parameter. Click 'OK' to close the 'Subreport Links' dialog box.

19. In the 'Field Explorer' of the main report, click 'Special Field'. Insert the 'PageNofM'
field in the Page Footer.

20. Preview the report to write the Table of Contents data to the database.

NOTE: 21. Refresh the report again and the Table of Contents will display the group and page
number values based on your report.
If changes are made
to the report that
affect X Training:
the page numbering,
refresh the report
twice to update the Learn more about Crystal Reports - Report Design.
TableOfContents
table. Refer to 'Courses & Schedules' at:

If the number of http://www.crystaldecisions.com/training


pages used by the
Table of
Contents changes,
the report must be
refreshed a third
time to update the

42 Business Objects • Crystal Reports Secrets


#10 How to add time fields

#10 How to add time fields


http://support.businessobjects.com/library/kbase/articles/c2008378.asp

X The information in the article refers to:

Seagate Crystal Reports 8


X Applies to:

Reported version and higher


summing time fields
converting seconds to hours, minutes, seconds
X Synopsis

The report contains a time field that displays in hh:mm:ss format.

How do you create a formula in Crystal Reports (CR) that adds more than one time
field and displays the total in the same format: hh:mm:ss?

For example:
1:45:01 + 1:45:01 should display 03:30:02 and not 2:90:02

X Solution

In order to get the sum of more than one time field and to display the total of the time
field in the
same format (hh:mm:ss) you must complete the following steps:

1. Convert all the time fields to a common time unit such as seconds

2. Calculate the total time in seconds

3. Convert the seconds back to hh:mm:ss format.

X Convert time fields to seconds

Convert the time fields to seconds so that a common time unit is used to sum up all
three different time units.

If your field is a datetime field, complete the following steps:

1. Create a new formula and call it @ConvertTimeToSeconds

43 Business Objects • Crystal Reports Secrets


#10 How to add time fields

2. To convert the datetime field to seconds, create a formula similar to the following:

local numbervar hours;


local numbervar minutes;
local numbervar seconds;

// Convert the hours to seconds by multiplying by


// 3600
hours := hour({@time}) * 3600;

// Convert the minutes to seconds by multiplying by


// 60
minutes := minute({@time}) * 60;
seconds := second({@time});

//add up all the seconds


hours + minutes + seconds;

To convert the string field, with the format of hh:mm:ss to seconds create a formula
similar to the following:

1. Create a new formula and call it @ConvertTimeStringToSeconds

2. Create a formula similar to the following to convert the string field to seconds:

local numbervar hours;


local numbervar minutes;
local numbervar seconds;

// Parse out the hours portion of the string and


// multiply by 3600 to convert to seconds
hours := tonumber({timestringfield}[1 to 2])* 3600;

// Parse out the minutes portion of the string and


// multiply by 60 to convert to seconds
minutes := tonumber({timestringfield}[4 to 5]) * 60;

// Parse out the seconds


seconds := tonumber({timestringfield}[7 to 8]);

// Add up all the seconds


hours + minutes + seconds;

X Calculate the total time in seconds

44 Business Objects • Crystal Reports Secrets


#10 How to add time fields

Create a summary formula that will sum the


@ConvertTimeToSeconds or @ConvertTimeStringToSeconds

1. Create a new formula and call it @TotalSeconds

2. To sum up either formula, create a formula


similar to the following:

sum(@ConvertTimeToSeconds, Group)
- OR -
sum(@ConvertTimeStringToSeconds, Group)

X Convert the seconds back to hh:mm:ss format

Create a formula that converts the @TotalSeconds results back to hh:mm:ss format.

1. Create a new formula and call it @ConvertTotalSeconds

2. To convert the results from @TotalSeconds back to hh:mm:ss format, create a formula
similar to the following:

local numbervar RemainingSeconds;


local numbervar Hours ;
local numbervar Minutes;
local numbervar Seconds;

//divide the @TotalSeconds by 3600 to calculate hours. Use truncate to remove the decimal
//portion.
Hours := truncate({@TotalSeconds} / 3600);

// Subtract the hours portion to get RemainingSeconds


RemainingSeconds := {@TotalSeconds} - (Hours * / 3600);

// Divide RemainingSeconds by 60 to get minutes. Use truncate to remove the decimal portion.
Minutes := truncate(RemainingSeconds/60);

// Subtract the Hours and Minutes and what is left over is seconds.
Seconds := {@Totalseconds} - (Hours * 3600) - (Minutes * 60);

// Format the hours, minutes, and seconds to hh:mm:ss


totext(Hours,"00") + ":" + totext(Minutes,"00") + ":" + totext(Seconds,"00")

45 Business Objects • Crystal Reports Secrets


#10 How to add time fields

X Training:

Learn more about Crystal Reports - Report Design.

Refer to 'Courses & Schedules' at:

http://www.crystaldecisions.com/training

46 Business Objects • Crystal Reports Secrets


#11 What font types are supported in Crystal Reports

#11 What font types are supported in Crystal Reports


http://support.businessobjects.com/library/kbase/articles/c2011820.asp

X The information in the article refers to:

Crystal Reports 9
X Applies to:

Reported version and higher


Supported exporting fonts
TTF
Exporting to PDF
X Synopsis

For Crystal Reports (CR), this knowledge base article answers the following questions
regarding embedded fonts:

a) What font types can be displayed within Crystal Reports?

b) What font types are supported when exporting to PDF?

c) How do you verify the embedded security level of a font?


X Solution

a) The following font types can be displayed within Crystal Reports:

· True Type Fonts (TTF)


· True Type Collection (TTC)
· Printer Font Metrics (PFM)
· Adobe Font Metrics (AFM)
· Printer Font Binary (PFB)
· Printer Font ASCII (PFA)

NOTE:
b) The following font types are supported when exporting to PDF:
Font File Names
· True Type Fonts (TTF)
(FONT) is a font
· True Type Collection (TTC)
type that is not
supported by
When exporting a report that contains a font type other than TTF or TTC to PDF
Crystal Reports
format, the font is not successfully exported or the following error message appears:

47 Business Objects • Crystal Reports Secrets


#11 What font types are supported in Crystal Reports

"<Font name> cannot be found."

c) To verify the embedded security level of a font, review the font properties. If the
security level contains "No-embedding" permissions, then exporting to PDF will not be
NOTE:
successful.
For the utility to
True Type Fonts (TTF) has embedding permissions that determine if they can be
allow you to view
converted into an embedded font format.
the embedded
security level of a
The permissions associated with the embedded security level of a font are as follows:
font, download the
"Font properties
· No-embedding - This does not allow fonts to be embedded. Contact the font vendor
extension" from
to request a possible upgrade to an embeddable font.
Microsoft's web site
at:
· Print and preview - This allows fonts to be embedded. However, only within pages
that remains static on the client computer. If a page allows fonts to be changed, then
www.microsoft.com
editable or installable fonts are required. Examples of a page that allows fonts to be
/typography
changed are an online Java-based word processor or an email editor.

· Editable - This allows fonts to be embedded using a tool such as Microsoft Web
Embedding Fonts Tools (WEFT) beyond the limitations of the "Print and preview"
permissions.

· Installable - This allows fonts to be embedded similar to the "Editable" permissions.


Note that installable fonts are not installed in the visitors' fonts folder.

X Summary

Not all fonts that can be displayed in Crystal Reports are supported when exporting to
PDF. Since PDF format embeds fonts, the font types that are exported must allow
embedding. Embedding permissions are determined by the font vendor.

48 Business Objects • Crystal Reports Secrets


#11 What font types are supported in Crystal Reports

X Background Information

New to version 9, Crystal Reports supports Unicode. Therefore, double-byte characters


can be displayed in Crystal Reports.

Also, support for exporting embedded fonts is new to Crystal Reports 9.

X More Information

Search for "Embedding Fonts" or "About Font Embedding" on the Microsoft support site
at:
http://support.microsoft.com

Search for "Font Format Types" or "Font File Formats" on the Adobe support site at:
http://support.adobe.com

X Related Information

Search for the file name, Scrprinterdependency.pdf, on our support site at:
http://support.crystaldecisions.com/docs

Search for the knowledge base articles, c2011114 and c2010555, on our support site at:
http://support.crystaldecisions.com/kbase

X Training:

Learn more about Crystal Reports - Report Design.

Refer to 'Courses & Schedules' at:

http://www.crystaldecisions.com/training

49 Business Objects • Crystal Reports Secrets


#12 How to format specific words or characters within a string

#12 How to format specific words or characters within a string


http://support.businessobjects.com/library/kbase/articles/c2015491.asp

X The information in the article refers to:

Crystal Reports 8.5


X Applies to:

Reported version and higher


Formatting fields
Word or character formatting
HTML
X Synopsis

In Crystal Reports (CR) there is no option to format occurrences of a specific word or


character, for example, bold or underline, within a string field.

How can you format occurrences of a specific word or character within a string field?
X Solution

To format occurrences of a specific word or character within a string field, use the
'Replace' function in a formula to replace the word or character.

For example, to bold all occurrences of the word "City' in the Customer Name field of
the Xtreme sample database, use this formula:
//@boldcity
//This is the formula name
NOTE:
Replace({Customer.Customer Name}, "City", "<b>City</b>")
Word or character Place this formula field on the report instead of the database field 'Customer Name'
formatting is and then select HTML Text Interpretation for the paragraph format as follows:
limited to the
supported HTML 1. Right-click the formula field and click the
tags. A list of 'Paragraph' tab in the Format Editor.
supported HTML
tags can be found 2. In the 'Text interpretation' list, click 'HTML
in the on-line help Text'.
files by pressing
F1. 3. Click 'OK' to close the Format Editor.

50 Business Objects • Crystal Reports Secrets


#12 How to format specific words or characters within a string

X Training:

Learn more about fonts in Crystal Reports.

Refer to 'Courses & Schedules' at:

http://www.crystaldecisions.com/training

51 Business Objects • Crystal Reports Secrets


#13 How to Display a Date Range Parameter on a Report

#13 How to Display a Date Range Parameter on a Report


http://support.businessobjects.com/library/kbase/articles/c2000534.asp
X The information in the article refers to:

Seagate Info, Crystal Reports 6

X Applies to:

Reported version and higher


Parameter fields
Date range selection formulas in version 5, 6, & 7
Displaying the date range in a report
X Synopsis

A report uses parameter fields to prompt you for a start and end date. These dates are
then used in the report's record selection formula.

To display the date range for this report, a formula similar to the example below is
placed in the Report Header:
//{@DateRange}

WhilePrintingRecords;
DateVar date1;
DateVar date2;
date1:=Minimum ({Datefield});
date2:=Maximum ({Datefield});
"my selection is: " + totext(date1) + " " + totext(date2)

However, when entering a date that is not in the database, this formula returns
confusing results.

For example:
The database contains date values from November 3rd (11/3/97) to November 30
(11/30/97).

If you enter '11/1/97' as the start date, and '11/30/97' as the end date, the @DateRange
formula in the Report Header displays "11/3/97 - 11/30/97".

This happens because there are no records for November 1st and 2nd.

How can you resolve this issue?

52 Business Objects • Crystal Reports Secrets


#13 How to Display a Date Range Parameter on a Report

X Solution

NOTE: To display a parameter-based date range for a report, regardless of whether thos dates
are in the database, use text objects.
In Crystal Reports
version 7 or higher, Using Text Objects to Display Date Range:
you can create ranged
parameters. 1. On the 'Insert' menu, click 'Text Object'. Place the text object in the Report Header.

This means that 2. On the 'Insert' menu, click 'Parameter fields'. This opens the 'Parameter fields' tab of
instead of creating the 'Insert fields' dialog box.
both a start and end
parameter, you only 3. Click the Start Date parameter and insert it into the text object.
need one date
parameter, which 4. Press the spacebar to insert a space in the text object, then type the string "to"
prompts for the start (without the quotes).
AND end dates.
5. Go back to the 'Insert fields' dialog box to insert the End Date parameter into the text
To learn how to use object, after the string 'to'. The text object now appears similar to this:
ranged parameters,
please consult chapter [{?pm-startdate} to {?pm-enddate}]
on parameters in the
Crystal Reports User This displays the date range that was entered for this report.
Guide:

· Chapter 16 of the CR
version 7 User Guide X Training:

· Chapter 22 of the CR
version 8 User Guide. Learn more about Crystal Reports - Report Design.

To display the date Refer to 'Courses & Schedules' at:


range using Range
Parameters, please see http://www.crystaldecisions.com/training
Knowledge Base article
C2002512

53 Business Objects • Crystal Reports Secrets


#14 How to suppress a blank subreport

#14 How to suppress a blank subreport


http://support.businessobjects.com/library/kbase/articles/c2011893.asp

X The information in the article refers to:

Crystal Reports 9
X Applies to:

Reported version and higher


'Suppress Blank Subpreport' option
Displaying subreports
Suppress blank section
X Synopsis

In Crystal Reports (CR) 9, how is a subreport suppressed if it contains no data? Also,


how is a section suppressed if it contains a blank subreport?
X Solution

To suppress a blank subreport, select the 'Suppress Blank Subreport' check box. This
feature is new to version 9 of Crystal Reports.

To suppress a section that contains a blank subreport, select the 'Suppress Blank
Section' check box.
X How to Suppress a Blank Subreport and then Suppress the Section

1. Right-click the subreport object and select 'Format Subreport'.

2. In the Format Editor dialog box, click the Subreport tab.

3. Select the 'Suppress Blank Subreport' check box.

4. Click 'OK' to exit the Format Editor dialog box.

5. Right-click the section containing the subreport and select 'Section Expert'.

6. In the Section Expert dialog box, select the 'Suppress Blank Section' check box.

7. Click 'OK' to exit the Section Expert dialog box.

54 Business Objects • Crystal Reports Secrets


#14 How to suppress a blank subreport

Upon selecting the 'Suppress Blank Subreport' and 'Suppress Blank Section' check
boxes, the subreport and section will not display on the main report when no data is
contained in the subreport.
X Background

In Crystal Reports 8.5 and earlier, a blank subreport cannot be suppressed. The blank
subreport is recognized as an object in the section. Therefore, a section containing a
blank subreport cannot be suppressed.

For more information on how to workaround this issue in CR 8.5 and earlier, refer to our
knowledge base article c2005853.

X Training:

Learn more about subreports in Crystal Reports.

Refer to 'Courses & Schedules' at:

http://www.crystaldecisions.com/training

55 Business Objects • Crystal Reports Secrets


#15 How to deploy an application that uses Crystal Reports
and VS .NET

#15 How to deploy an application that uses Crystal Reports and VS


.NET?
http://support.businessobjects.com/library/kbase/articles/c2013175.asp
X The information in the article refers to:

Crystal Reports for Visual Studio 9


X Applies to:

Reported version only


Application Deployment
Runtime Files
X Synopsis

How do you deploy an application that uses Crystal Reports and Visual Studio .NET?
X Solution

Before you deploy an application that uses Crystal Reports and Visual Studio .NET
you must confirm the version of Crystal Reports being used with Visual Studio .NET.
The possible versions are:
- Crystal Reports for Visual Studio .NET 2002
- Crystal Reports for Visual Studio .NET 2003
- Crystal Reports 9
- Crystal Reports 10

To do this, check the assembly version of the Crystal Reports managed components.
The Crystal Reports managed components include:
- CrystalDecisions.CrystalReports.Engine
- CrystalDecisions.Shared
- CrystalDecisions.Reportsource
- CrystalDecisions.Web
- CrystalDecisions.Windows.Forms.

In your Visual Studio .NET 'Solution Explorer', expand 'References', right-click on a


Crystal Reports managed component, select 'Properties' and check the version
property. The assembly version must be the same for all the Crystal Reports managed
components referenced in the solution.

· If your Crystal Reports managed assemblies are version 9.1.3300, your application
uses Crystal Reports for Visual Studio .NET 2002.

56 Business Objects • Crystal Reports Secrets


#15 How to deploy an application that uses Crystal Reports
and VS .NET

· If your Crystal Reports managed assemblies are version 9.1.5000, your application
uses Crystal Reports for Visual Studio .NET 2003.
· If your Crystal Reports managed assemblies are version 9.2.3300, your application
uses Crystal Reports 9.

· If your Crystal Reports managed assemblies are version 10.0.3300, your application
uses Crystal Reports 10.

X To deploy an application that uses Crystal Reports for Visual Studio .NET 2002

1. Ensure that the assembly version of the Crystal Reports managed components is
9.1.3300.

2. Go to http://support.businessobjects.com/search and download


"crnet_deployment.pdf".

3. Open Crnet_deployment.pdf and refer to the 'Crystal Reports Bundled Version with
VS 2002' section.

X To deploy an application that uses Crystal Reports for Visual Studio .NET 2003

1. Ensure that the assembly version of the Crystal Reports managed components is
9.1.5000.

2. Go to http://support.businessobjects.com/search and download


"crnet_deployment.pdf".

3. Open Crnet_deployment.pdf and refer to the 'Crystal Reports Bundled Version with
VS 2003' section.

X To deploy an application that uses Crystal Reports 9

1. Ensure that the assembly version of the Crystal Reports


managed components is 9.2.3300.

2. Go to http://support.businessobjects.com/search and
download "crnet_deployment.pdf".

3. Open Crnet_deployment.pdf and refer to the

57 Business Objects • Crystal Reports Secrets


#15 How to deploy an application that uses Crystal Reports
and VS .NET

'Crystal Reports 9 Full Version with VS2002 or VS2003'


section.

X To deploy an application that uses Crystal Reports 10

1. Ensure that the assembly version of the Crystal Reports


managed components is 10.0.3300.

2. Go to http://support.businessobjects.com/search and
download "deploying_cr10_net.pdf".

X Training:

Learn more about Crystal Reports.

Refer to 'Courses & Schedules' at:

http://www.crystaldecisions.com/training

58 Business Objects • Crystal Reports Secrets


#16 What is Unicows.dll and where can you find it?

#16 What is Unicows.dll and where can you find it?


http://support.businessobjects.com/library/kbase/articles/c2011871.asp
X The information in the article refers to:

Crystal Reports 9
X Applies to:

Reported version only


Unicode runtime
Windows 9x/ME
X Synopsis

The Crystal Reports (CR) 9 Developer Runtime Help (Runtime.chm) lists Unicows.dll
as a dependency file for the Report Designer Component (RDC) and Crystal Print
Engine API.

What is Unicows.dll and where can you find it?


X Solution
NOTE: Unicows.dll is a wrapper to provide Unicode support for Windows 9x and ME
(Windows NT, 2000, and XP already provide Unicode support).
Windows 9.x and
ME are not The Unicows.dll is contained in the RDC 9 merge modules. To download the RDC 9
supported merge modules, go to http://support.businessobjects.com/search and download
platforms for Cr9rdcmergemodules.zip.
Crystal Reports
(CR) 10 and later. For information on deploying an RDC 9 application, go to
Therefore, http://support.businessobjects.com/search and download rdc9_deployment.pdf.
Unicows.dll is not
supported for the Search for this file at:
Windows 9.x and http://support.businessobjects.com/search
ME operating
X Training:

Refer to 'Courses & Schedules' at:

http://www.crystaldecisions.com/training

59 Business Objects • Crystal Reports Secrets


#17 How to change the data source using CR for VS .NET
application

#17 How to change the data source using CR for VS .NET application
http://support.businessobjects.com/library/kbase/articles/c2011464.asp
X The information in the article refers to:

Crystal Reports for Visual Studio .NET


X Applies to:

Reported version only


Database connectivity
Change Database and Server
X Synopsis

An application uses Crystal Reports for Visual Studio .NET as the reporting
development tool.

How do you change the database and server in a report at runtime?

For example, if a report is designed against the 'pubs1' database and the 'server1'
server, how can you change the database to 'pubs2' and the server to 'server2'?
X Solution
To change the database and server at runtime, copy one of the following code samples into your class
(use the logon method defined in the code to change the database and server):

--------------------- C# .NET ---------------------

// Helper method that iterates through all tables


// in a report document

bool ApplyLogon(ReportDocument cr, ConnectionInfo ci)


{
TableLogOnInfo li;

60 Business Objects • Crystal Reports Secrets


#17 How to change the data source using CR for VS .NET
application

CAUTION:

• When using ODBC, the DSN name is the server name. The DSN should be under the System
DSN, and not under the User DSN.

• The Logon method cannot change database file name when using DAO (Microsoft Access
File/.mdb).

• If you have a subreport that connects to a different database or server than your main report,
use the ApplyLogon method instead of the Logon method. When using the ApplyLogon
method, ensure you iterate through each subreports.

• It is not possible to use the CR for VS .NET SDK to change a report from using SQL
Authentication to Windows Authentication, or vice versa. This functionality is available
through the Report Application Server (RAS) .NET SDK or Report Designer Component (RDC).

// for each table apply connection info


foreach (Table tbl in cr.Database.Tables)
{
li = tbl.LogOnInfo;
li.ConnectionInfo = ci;
tbl.ApplyLogOnInfo(li);

// check if logon was successful


// if TestConnectivity returns false, check
// logon credentials

if (tbl.TestConnectivity())
{
// drop fully qualified table location
if (tbl.Location.IndexOf(".") > 0)
{
tbl.Location = tbl.Location.Substring(tbl.Location.LastIndexOf(".") + 1);
}
else tbl.Location = tbl.Location;
}
else return(false)
}
return(true);
}

// The Logon method iterates through all tables

61 Business Objects • Crystal Reports Secrets


#17 How to change the data source using CR for VS .NET
application

bool Logon(ReportDocument cr, string server, string db, string id, string pass)
{
ConnectionInfo ci = new ConnectionInfo();
SubreportObject subObj;

ci.ServerName = server;
ci.DatabaseName = db;
ci.UserID = id;
ci.Password = pass;
if (!ApplyLogon(cr, ci)) return (false);

foreach (ReportObject obj in cr.ReportDefinition.ReportObjects)


{
if (obj.Kind == ReportObjectKind.SubreportObject)
{
subObj = (SubreportObject)obj;
if
(!ApplyLogon(cr.OpenSubreport(subObj.SubreportName), ci)) return(false);
}
}
return (true);
}

---------------------- VB .NET ---------------------

Function ApplyLogon(ByVal cr As ReportDocument, ByVal ci As ConnectionInfo) As Boolean

Dim li As TableLogOnInfo
Dim tbl As Table

' for each table apply connection info

For Each tbl In cr.Database.Tables


li = tbl.LogOnInfo
li.ConnectionInfo = ci
tbl.ApplyLogOnInfo(li)

' check if logon was successful


' if TestConnectivity returns false,
' check logon credentials

If (tbl.TestConnectivity()) Then
'drop fully qualified table location
If (tbl.Location.IndexOf(".") > 0)
Then
tbl.Location = tbl.Location.Substring(tbl.Location.LastIndexOf(".") + 1)

62 Business Objects • Crystal Reports Secrets


#17 How to change the data source using CR for VS .NET
application

Else
tbl.Location = tbl.Location
End If
Else
Return False
End If
Return True

Next

End Function

'The Logon method iterates through all tables


Function Logon(ByVal cr As ReportDocument, ByVal server As String, ByVal db As String,
ByVal id As String, ByVal pass As String) As Boolean

Dim ci As New ConnectionInfo()


Dim subObj As SubreportObject

ci.ServerName = server
ci.DatabaseName = db
ci.UserID = id
ci.Password = pass

If Not (ApplyLogon(cr, ci)) Then


Return False
End If

Dim obj As ReportObject

For Each obj In


cr.ReportDefinition.ReportObjects
If (obj.Kind =
ReportObjectKind.SubreportObject) Then
subObj = CType(obj, SubreportObject)
If Not
(ApplyLogon(cr.OpenSubreport(subObj.SubreportName),
ci)) Then
Return False
End If
End If
Next
Return True
End Function

63 Business Objects • Crystal Reports Secrets


#17 How to change the data source using CR for VS .NET
application

X Training:

Refer to 'Courses & Schedules' at:

http://www.crystaldecisions.com/training

64 Business Objects • Crystal Reports Secrets


#18 How to pass Database logon info to a Crystal Report at
runtime in VB .NET

#18 How to pass Database logon info to a Crystal Report at runtime


in VB .NET
http://support.businessobjects.com/library/kbase/articles/c2010371.asp
X The information in the article refers to:

Crystal Reports for Visual Studio .NET


X Applies to:

Reported version only


Logon Information
TableLogonInfo
X Synopsis:

A VB .NET application uses Crystal Reports for Visual Studio .NET as the reporting
development tool.

How do you pass database logon information to a Crystal Report at runtime in this
VB .NET application?
X Solution:

To pass logon information to a Crystal Report at runtime, use the following code
sample:

<VB .NET>
-----------

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Dim crtableLogoninfos As New TableLogOnInfos()


Dim crtableLogoninfo As New TableLogOnInfo()
Dim crConnectionInfo As New ConnectionInfo()
Dim CrTables As Tables
Dim CrTable As Table
Dim TableCounter

'If you are using a Strongly Typed report (Imported in


'your project) named CrystalReport1.rpt use the
'following:

Dim crReportDocument As New CrystalReport1()

65 Business Objects • Crystal Reports Secrets


#18 How to pass Database logon info to a Crystal Report at
runtime in VB .NET

'If you are using a Non-Typed report, and loading a report outside of the project, use the
'following:

Dim crReportDocument As New ReportDocument()

crReportDocument.Load("c:\myReports\myReport.rpt")

'Set the ConnectionInfo properties for logging on to the Database


'If you are using ODBC, this should be the DSN name NOT the physical server name. If
'you are NOT using ODBC, this should be the physical server name

With crConnectionInfo
.ServerName = "DSN or Server Name"

'If you are connecting to Oracle there is no DatabaseName. Use an empty string.
'For example, .DatabaseName = ""

.DatabaseName = "DatabaseName"
.UserID = "Your User ID"
.Password = "Your Password"
End With

'This code works for both user tables and stored procedures. Set the CrTables to the Tables
'collection of the report

CrTables = crReportDocument.Database.Tables

'Loop through each table in the report and apply the LogonInfo information

For Each CrTable in CrTables


CrTableLogonInfo = CrTable.LogonInfo
CrTableLogonInfo.ConnectionInfo =
crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)

'If your DatabaseName is changing at runtime, specify the table location.


'For example, when you are reporting off of a Northwind database on SQL server you
'should have the following line of code:

crTable.Location = "Northwind.dbo." &


crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1)
Next

'Set the viewer to the report object to be previewed.

CrystalReportViewer1.ReportSource = crReportDocument

66 Business Objects • Crystal Reports Secrets


#18 How to pass Database logon info to a Crystal Report at
runtime in VB .NET

<C# .NET>
-----------

using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

private CrystalReport1 crReportDocument = new


CrystalReport1 ();
private Database crDatabase;
private Tables crTables;
private Table crTable;
private TableLogOnInfo crTableLogOnInfo;
private ConnectionInfo crConnectionInfo = new
ConnectionInfo ();

//Setup the connection information structure to log on to the data source for the report.
// If using ODBC, this should be the DSN. If using OLEDB, etc, this should be the physical
//server name

crConnectionInfo.ServerName = "DSN or
Server Name";

// If you are connecting to Oracle there is no


// DatabaseName. Use an empty
// string i.e. crConnectionInfo.DatabaseName = "";

crConnectionInfo.DatabaseName = "DatabaseName";
crConnectionInfo.UserID = "Your UserID";
crConnectionInfo.Password = "Your Password";

// This code works for both user tables and stored procedures

//Get the table information from the report


crDatabase = crReportDocument.Database;
crTables = crDatabase.Tables;

//Loop through all tables in the report and apply the connection information for each table.
for (int i = 0; i < crTables.Count; i++)
{
crTable = crTables [i];
crTableLogOnInfo = crTable.LogOnInfo;
crTableLogOnInfo.ConnectionInfo =
crConnectionInfo;
crTable.ApplyLogOnInfo(crTableLogOnInfo);

67 Business Objects • Crystal Reports Secrets


#18 How to pass Database logon info to a Crystal Report at
runtime in VB .NET

//If your DatabaseName is changing at runtime, specify the table location. For example, when
//you are reporting off of a Northwind database on SQL server you should have the following
//line of code:

crTable.Location = "Northwind.dbo." +
crTable.Location.Substring(crTable.Location.LastIndexOf (".") + 1)
}

//Set the viewer to the report object to be previewed.

crystalReportViewer1.ReportSource = crReportDocument;

CAUTION:

• If you're using a web application make sure that, you do not specify or call the DataBind in your code
as this will nullify the code above.

If the above code still results in a LogOn Failure in a Web application (ASP.NET), please refer to the
Knowledge base article c2010867 (For Windows 2000) or c2013758 (Windows 2003 server (IIS6)), and
make sure ASPNET account has enough access to the database, reports, and the application
directories.

• If you are changing database at runtime, it is important that you specify the table location after you
apply logon information (this is a case sensitive property). You can either specify the tablename only or
the fully qualified tablename such as:

crTable.location = "databaseName.dbo.tablename"

• If you are reporting off of an Access Database, then you only need to specify either the ServerName or
DatabaseName to the ConnectionInfo Object depending on how you are connecting to Access.

For example, if you are connecting to Access through ODBC, then you just need to set the
DatabaseName for the ConnectionInfo object as the following:

With crConnectionInfo
.DatabaseName = "C:\mydatabase\mydata.mdb"
End With
• If you are connecting to Access via OLEDB, then you
just need to set the ServerName:

With crConnectionInfo
.ServerName = "C:\mydatabase\mydata.mdb"
End With

68 Business Objects • Crystal Reports Secrets


#18 How to pass Database logon info to a Crystal Report at
runtime in VB .NET

X Training:

Refer to 'Courses & Schedules' at:

http://www.crystaldecisions.com/training

69 Business Objects • Crystal Reports Secrets


#19 How to create a report and add a parameter field using
Report Creation API

#19 How to create a report and add a parameter field using Report
Creation API
http://support.businessobjects.com/library/kbase/articles/c2007184.asp

X The information in the article refers to:

Crystal Reports, Report Designer Component 8


X Applies to:

Reported version and higher


Report Creations API
Creating a Parameter field at runtime
Including the Parameter field in a record selection formual
X Synopsis
NOTE:
For more articles on This article is part of a series of Knowledge Base articles that demonstrate the Report
using the Report Creation API (RCAPI) available in the Report Designer Component for Crystal Reports
Designer Version 8 Developer Edition.
Component's
Report Creation This article demonstrates how to:
API search on the
keyword 'RCAPI' at - Create a report at runtime (RCAPI Method: 'NewReport')
http://support.crys - Add a table from a Native connection to Microsoft Access. (RCAPI Method: 'Add')
taldecisions.com/k - Add a parameter field to the ParameterFieldDefinitions collection. (RCAPI Method:
base 'Add')
- Create a record selection formula that includes the parameter field.
All Runtime Report - Add database fields to the report. (RCAPI Method: 'AddFieldObject')
Creation - Display the report.
functionality
X Solution
requires licensing.
For more This tutorial assumes that the developer has prior knowledge of Microsoft Visual Basic,
information, please Crystal Reports, and the Report Designer Component.
visit
http://www.crystal The following procedure and sample code creates an application that demonstrates the
decisions.com/pro RCAPI methods outlined in the Synopsis.
ducts/crystalreport
1. On the 'Project' menu in Microsoft Visual Basic click 'References'. The 'References'
dialog box appears.

70 Business Objects • Crystal Reports Secrets


#19 How to create a report and add a parameter field using
Report Creation API

NOTE: 2. In the dialog box select the 'Crystal Report 8 ActiveX Designer Run Time Library'
check box. Click 'OK' to save the changes.
For more
information on the 3. On the 'Project' menu, click 'Components'. The 'Components' dialog box appears.
RCAPI refer to the
'Seagate Crystal 4. In the dialog box click 'Controls', select the 'Crystal Report Viewer' check box and
Reports 8 Technical then click 'Apply'. This adds the CRViewer icon to the Microsoft Visual Basic toolbar.
Reference Guide'. Click 'OK' to save the changes.
The guide can be
found in the Docs 5. On the Microsoft Visual Basic toolbar double-click 'CRViewer'. The Crystal Report
folder of the Crystal Viewer is added to the form.
Report 8 installation
CD. 6. Double-click 'Form1' to open the 'Code' module. Insert the 'Sample RDCAPI code' in
the code module.

7. Once you have inserted the code, on the 'Run' menu, click 'Start' to run the
application.
Option Explicit
'RDC Runtime Objects used in this sample.
Dim crApplication As CRAXDRT.Application
Dim crReport As CRAXDRT.Report

'***********************************************
'The Form_Load event creates an instance of the RDC engine, then makes calls to routines
'that will setup the report and finally display the report in the Crystal Report Viewer control.
'***********************************************

Private Sub Form_Load()

'Create an instance of the RDC engine


Set crApplication = New CRAXDRT.Application

'Create a new report


Set crReport = crApplication.NewReport

'Calling a routine that will add a database connection for the report
Call AddDatabase

'Calling a routine that will add objects to the Detail section.


Call AddToDetails

'Calling a routine that will add a parameter field to the ParameterFieldDefinitions collection,
'and include the parameter in a record selection formula.
Call AddParameterField

71 Business Objects • Crystal Reports Secrets


#19 How to create a report and add a parameter field using
Report Creation API

'Set the Report Viewer control to a report to view


CRViewer1.ReportSource = crReport

'Display the report in the Crystal Report Viewer


CRViewer1.ViewReport

End Sub

'***********************************************
'The AddDatabase() routine is used to add a native database connection to the sample
'database, Xtreme.MDB. In this sample the 'Customer' table is being added.
'***********************************************

Public Sub AddDatabase()


'Variables used to setup the Database connection
Dim crDBTables As CRAXDRT.DatabaseTables
Dim sDatabasePath As String
Dim sTableName As String

'Get the Tables collection because it has the Add() method needed
'to add a connection to the report
Set crDBTables = crReport.Database.Tables

'Set the values for the connection variables The full path and name of the Access database.
'The database resides in the same directory as the application
' sDatabasePath = App.Path & "\xtreme.mdb"

'The name of the Access table


sTableName = "Customer"

'Use the .Add() method to add the database table to the report. There are several optional
'arguments for the Add method. Which arguments are passed will depend on the type of
'database, the type of table and the type of connection.

'Add the 'Customer' table


crDBTables.Add sDatabasePath, sTableName
End Sub

'***********************************************
'The AddToDetails () routine is used to add objects to the Detail section. In this case, two 'fields
from the 'Customer' table are added.
'***********************************************
Public Sub AddToDetails()
Dim crSection As CRAXDRT.Section
Dim crFieldObject As CRAXDRT.FieldObject

72 Business Objects • Crystal Reports Secrets


#19 How to create a report and add a parameter field using
Report Creation API

'****Add database fields and the formula field to the Details section*****

'Since we are working with the Details section of the report, we need to get the 'D' section of 'the
report.
Set crSection = crReport.Sections.Item("D")

'**Add the 'Customer Name and 'Last Year's Sales' fields to the details section**
'Set a Field object to the AddFieldObject method of the Detail Section
'The Field parameter is set to the table.fieldname
'The Left and Top parameters are passed as integers to position the field
Set crFieldObject = crSection.AddFieldObject("{Customer.Customer Name}", 600, 0)

Set crFieldObject = crSection.AddFieldObject("{Customer.Last Year's Sales}", 3720, 0)

End Sub

'***********************************************
'The AddParameterField () routine is used to add a parameter field to the
'ParameterFieldDefinitions collection. The default values for the parameter field will be set and
'the parameter will be included in a record selection formula
'***********************************************
Public Sub AddParameterField()

Dim crParameterFields As CRAXDRT.ParameterFieldDefinitions

'Since we are adding a formula field to the ParameterFieldDefinitions collection we need to get
'the ParameterFields from the report object Set crParameterFields = crReport.ParameterFields

'Add a parameter field to the ParameterFieldDefinitions Collection The ParameterName


'parameter is set to the name of the new parameter The ValueType parameter specifies the
'value type to be passed to the parameter crParameterFields.Add "Sales Maximum Value",
'crCurrencyField

73 Business Objects • Crystal Reports Secrets


#19 How to create a report and add a parameter field using
Report Creation API

'With the new parameter field set the default values Set the Value to be a single discrete
'value and do not allow multiple values This is the first parameter field created in the report so
'we access the first item in the ParameterFieldDefinitions collection

With crReport.ParameterFields(1)
.AddDefaultValue 50
.AddDefaultValue 500
.AddDefaultValue 10000
.AddDefaultValue 25000
.AddDefaultValue 50000
.AddDefaultValue 100000
.AddDefaultValue 150000
.AddDefaultValue 200000
.AddDefaultValue 250000
.AddDefaultValue 500000
.AddDefaultValue 1000000
.DiscreteOrRangeKind = crDiscreteValue
.EnableMultipleValues = False
End With

'Pass a record selection formula to the report The record selection formula contains the newly
'created parameter When the report is run the parameter will prompt the user. The default
'values set previously will be available to the user to select the name of the parameter field in
'the recordslection formula will follow this format:
'{? + The name of the new parameterfield + }
'crReport.RecordSelectionFormula = "{Customer.Last Year's Sales} < {?Sales Maximum 'Value}"

End Sub

'***********************************************
'The Form_Resize event is used to size the Crystal Report
'Viewer control to the size of the Parent form (Form1).
'***********************************************
Private Sub Form_Resize()

With CRViewer1
.Top = 0
.Left = 0
.Width = Me.ScaleWidth
.Height = Me.ScaleHeight
End With

End Sub

'***********************************************
'The Form_Unload event is used to clean up the objects

74 Business Objects • Crystal Reports Secrets


#19 How to create a report and add a parameter field using
Report Creation API

'used by the sample application.


'***********************************************
Private Sub Form_Unload(Cancel As Integer)

'Destroy the Report object


Set crReport = Nothing

'Destroy the Application object


Set crApplication = Nothing

End Sub

X Training:

Refer to 'Courses & Schedules' at:

http://www.crystaldecisions.com/training

75 Business Objects • Crystal Reports Secrets


#20 Crystal Reports for Visual Studio .NET documentation

#20 Crystal Reports for Visual Studio .NET documentation


http://support.businessobjects.com/library/kbase/articles/c2010837.asp

X The information in the article refers to:

Crystal Reports for Visual Studio .NET


X Applies to:

Reported version only


Documentation

X Synopsis

Where can you find documentation or help files for Crystal Reports for Visual Studio
.NET (VS .NET)?
X Solution

Crystal Reports documentation is included as part of the VS .NET documentation.

Documentation is available online at the Microsoft Developer Network (MSDN) web


site and is also bundled with VS .NET as part of MSDN. The following link leads
directly to the Crystal Reports for VS .NET documentation in the MSDN Library:
MSDN Website:
http://msdn.microsoft.com/library/?url=/library/en-
us/crystlmn/html/crconcrystalreports.asp?frame=true
Microsoft Visual Studio .NET

You can also find CR for VS .NET resources on the Business Objects support site.

Documentation is accessible through a variety of methods in VS .NET. The common ones are:

· Searching for "Crystal Reports" in the VS .NET documentation index.


· ontext sensitive help: Click the insertion point on a Crystal property method or object in the VS
.NET code editor, and press the F1 key. A tab appears in the VS.NET IDE with documentation on
what code is covered by the insertion point
http://www.businessobjects.com/services/training/crystalreports.asp

76 Business Objects • Crystal Reports Secrets


#20 Crystal Reports for Visual Studio .NET documentation

Business Objects Support Site

· Download .NET documentation at


http://support.businessobjects.com/library/docfiles/cps10/docs_en.asp

· Download VS .NET sample applications at


http://support.businessobjects.com/fix/samplescr.asp

· Download VS .NET white papers by searching for "crnet*" at


http://support.businessobjects.com/search

X Training:

Refer to 'Courses & Schedules' at:

http://www.crystaldecisions.com/training

77 Business Objects • Crystal Reports Secrets


Summary

Summary:

Whether you are a novice or an expert, there are additional resources available to help
you get more from your investment. To investigate all of the options, please visit
http://www.businessobjects.com/services/training/crystalreports.asp

You might also want to consider certification. “73% of employees surveyed said
certification played a significant role in career advancement.”
(Certification Magazine’s 2003 Salary Survey, December 2003.)
http://www.businessobjects.com/services/training/crystal/certification.asp

A final tip: If you are responsible for team or organization training or if user adoption is
important to you, we have a white paper just for you. The comprehensive report is free
of charge – download your copy by visiting www.businessobjects.com/training

Thank you for investing the time to learn our Crystal Reports secrets. We hope that you
already feel more confident in your ability to design better reports, faster.

If you have any questions, please contact us. Our customer service representatives are
ready to help you. In North America call 1-866-665-4176 or contact a worldwide office.

78 Business Objects • Crystal Reports Secrets


Worldwide contact information

Americas
Business Objects Americas
3030 Orchard Parkway
San Jose, California 95134
USA
Tel: +1 408 953 6000
+1 800 877 2340

Asia-Pacific
Business Objects Asia Pacific Pte Ltd
350 Orchard Road
#20-04/06 Shaw House
238868
Singapore
Tel: +65 6887 4228

Europe, Middle East, Africa


Business Objects, SA
157-159 rue Anatole France
92309 Levallois-Perret Cedex
France
Tel: +33 1 41 25 21 21

Japan
Business Objects Japan K.K.
Head Office
Yebisu Garden Place Tower 28th Floor
4-20-3 Ebisu, Shibuya-ku
Tokyo 150-6028
Tel: +81 3 5720 3570

For a complete listing of our sales offices, please visit our website.
http://www.businessobjects.com

79 Business Objects • Crystal Reports Secrets

You might also like