Programming Samples

Click here to go to:

Excel VBA
MS Access
T-SQL
SSIS
SSRS
Crystal Reports
C# Code
ASP .NET Code
Oracle PL/SQL

Back to Home Page

Crystal Reports - Basic Formatting

Crystal Reports Formatting

This article covers some basic formatting of TextBoxes and fields in a Crystal Report.

Crystal Report Preview in Need of Formatting

The Preview of the Crystal Report is in need of some additional formatting. The Vendor Name is cut off and the Contact Name and Addresses require formatting. Also, I made a mistake in using the Country for the Grouping because all of the Vendors are located in the United States.

Crystal Reports Preview

The textboxes in the header need to be centered. In Propeties, the HorAlignment can be set to crHorCenterAlign.

Using a Crystal Report Formula

Crystal Reports TextBox Alignment

The appearance of the Contact Names does not look pleasing in the report. To fix this, the FirstName, MiddleName and LastName fields will be removed from the report by clicking on each textbox and pressing delete or right clicking and selecting Delete from the Context Menu. To create a new "field" that contains the complete name, a formula may be created. In the Field Explorer, right click on Formula Fields and click New.

Crystal Reports Formula Fields

The popup box requires a name to be entered (in this case, it is ContactName). Click Use Editor to get into edit mode for the formula.

Formula Name Popup

In the Editor, select Basic Syntax from the toolbar to create code in Visual Basic. The fields may be pulled from the ADO OLE DB connection or from the Report fields.

Crystal Reports Editor

The variable declared is called fullName. It is "built" by first assigning the FirstName field to it and then testing for a MiddleName with an If Then conditional statement. Finally, it is appended with the LastName field and then assigned the keyword formula.

Basic Syntax formula

The Vendor Address Lines and City, State, Zip fields do not flow nicely either. Add another Formula and name it VendorAddress and click Use Editor to edit the formula.

Formula for VendorAddress

The variable for the fullAddress is declared at the top of the code window. A conditional If Then statement tests for an AddressLine2 and appends it to the field if it exists. The City, State, and Zip fields are concatenated into a single line below the address line with a carriage return (Chr(10)).

Basic Syntax for VendorAddress formula

Formatting Crystal Report Objects

To make sure the Vendor Name field does not get truncated in the report, right click on the Name field and select Format Object.

Format Object

Click on the Can Grow checkbox which will allow the field to expand, if necessary. Click OK to close.

Format Editor

Crystal Report Group Expert

As stated at the beginning, all of the Vendors are in the United States. To select a different grouping (such as the StateProvinceName), right click on the report and click on Group Expert to get to the pop up.

Crystal Report Selection Group Expert

In the Group Expert, click on the left pointing arrow (<)to remove vVendor.Country from the Group By list and then in the Available Fields, select the vVendor.StateProvinceName and click the right pointing (>) arrow to add it to the Group By box. Click Options to set the Group Name at the top of each page.

Crystal Reports Group Expert

In the Group Options popup, select the Options tab and click in the checkbox labeled Repeat Group Header On Each Page. this will ensure that the Group Name (State Name) will appear at the top of the page in case the Group breaks across multiple pages.

Option for Group

The Design View of the completed report. @ContactName formula field replaces the FirstName, MiddleName, LastName fields. @VendorAddress formula field replaces AddressLine1, AddressLine2, City, State, and Zip fields. The GroupName has been changed to vVendor.StateProvinceName.

Crystal Report Design

Click Preview to view the formatted report.

Crystal Report Preview

That covers basic formatting for Crystal Reports. More complex topics are covered in other Crystal Reports articles on this site.