Adding Linear Barcodes In Crystal Reports Using Formula

To add a linear barcode in Crystal Reports, what you need is to create a formula field, calculate the barcode string for the field, and format the field with appropriate barcode fonts. Remember that many symbologies require start/stop characters as well as check characters - so you can not just format the field with a barcode font - you must convert the input to a valid barcode string.

There are two methods using external functions in Crystal Reports. The most widely used is to exploit the the Crystal Reports UFL (User Function Library). Anther method is to use Morovia Formula written in native Cyrstal Reports language. This article explains how to use Crystal Reports Formulas. If you are interested with working with UFL, click here.

Warning

Not all encoder functions are available in Crystal Reports Formula. Code128Ex and EAN128Ex are the two that have no formula couterparts.

Advantages of using Crystal Reports Formula:

  • The formulas are embedded in the report file itself so all you need is to distribute the report file and the font.

  • Formula is easy to to use and maintain.

Installing Formula

We use Crystal Reports version 9 for tutorial. If you are working on an earlier version the steps outlined still apply. You are authorized to use the Formulas provided by Morovia for free as long as you own a valid license to the font product. You are also allowed to distribute the formula with your report outside your organization with the purchase of a developer license.

The Morovia Formula component is included in every Fontware package (demo and release) as wells in Morovia Font Tools.

After you installed Morovia Font Tools, you can add Morovia Formulas into the Crystal Reports Repository to make them available to every new reports. To do this, perform the following steps:

  • Locate Morovia sample file (crLinearFormulas.rpt) under MoroviaFontTools folder (usually it is under c:\program files\common files\Morovia\MoroviaFontTools folder). Open the file in Crystal Report by double clicking the file in Windows explorer.

  • From the main menu select ReportFormula Workshop... to pop up the Formula Workshop. Expand the first node - Report Custom Function. Click every function to view the contents. Then click the Add to Repository button to add the function into Repository. Add every function into the Repository. If the program prompts that a version has already existed, click yes. After you finish, close the Formula Workshop and then close the sample file.

Now you are ready to use Morovia Formulas. You are now ready to use the functions.

Working with Crystal Reports

In the following tutorial we will start with a blank report. In the report we created several database fields. Now we want to add a barcode field which encodes shipping ID. We choose Code128C as the barcode format.

  1. First we switch to design view. This can be done with ViewDesign (Ctrl+D)

  2. Now choose ViewField Explorer to have Field Explorer appear at the right side of the work space.

  3. We are now ready to add the barcode field. Right click the Formula Fields to have the context menu pop up. Choose New...

  4. Give a name to this new filed. In our case we simply call it barcode.

  5. Click on the Use Expert button. The Formula Workshop dialog pops up. Find Morovia barcode functions under the Repository Customer FunctionsCrystal RepositoryMoroviaFontTools. If you can not find such section, it is likely that you did not add them into the respository.

  6. Select the appropriate barcode function (in our case is Code128C), double click it to make it appear in the bottom panel. Select the argument. Put the data field you want to encode. In our case, we put {Sheet1_.CustomerID} because that filed is what we want to present in barcode form. Note that this field needs to be a text string. You can use Crystal Reports function ToText to convert other format into text string.

  7. Dismiss the Formula workshop and return to the Field Explorer dialog.

  8. Drag the new filed from Field Explorer to anywhere you want to place in the report.

  9. Click on this new field, and format it with appropriate barcode font. In our case, we use MRV Code128SA and point size 12. Dismiss the Format dialog.

  10. Click on the Preview tab. the barcodes appear. We have successfully build a report with barcodes in minutes! Note that this tutorial uses the trial version of the Code128 Fontware, so the second barcode contains a demo watermark. This limitation will go away once you purchased the retail version.

Distributing your report

Once you finish the report design, you can distribute your report application with Crystal run time files, barcode fonts. You do not need to distribute Morovia Formulas, because they are included in the report file.

License Requirement

First you must obtain enough license from Morovia Corporation. You can either purchase single user license for every computer you are going to install; or purchase a Corporate license if you have a large install base within your organization. If you want to distribute outside your company, a developer license is required.

File List

Using the Formula method, you do not need to distribute any run time DLLs. However, you do need to distribute the font files which can be located in the Fontware folder under C:\program files\morovia.