5.4. Steps to add Barcodes to Crystal Reports

In the following tutorial we start with a blank report. In the report we have already created several report fields reflecting database fields. We now add the barcode to the report.

Procedure 5.1. Steps to add barcode to Crystal Reports

  1. Define the barcode trunk fields. A barcode trunk field is a formula field. Most likely you know what it is. To create a formula field, we need to enter the design view. It can be done by choosing View | Design or simply pressing CTRL+D.

  2. If the Field Explorer is invisible, select View | Field Explorer to have it appear in the workspace.

  3. Right click on the Formula Fields. From the context menu, select New... to add a formula field.
  4. Give a name to this new field. In our case we call it barcode_trunk1. You can use any names compatible with your naming convention.
  5. Click on the Use Editor button. The Formula Editor pops up. Find Morovia barcode functions under the Additional Functions | Visual Basic UFLs section.
  6. Select the the function MoroviaDataMatrixEncode, double click it to make it appear in the bottom panel. Move the cursor in between the parenthesis. Put the data field you want to encode. In our case, we put {TestData.Data} because that filed is what we want to present in barcode form. Note that this field must be a text string. You can use Crystal Reports function ToText to convert other formats into text string. Move the cursor to the next field, and type 1.
  7. Dismiss the Formula Editor and return to the Field Explorer dialog.
  8. Based on the calculation from the GUI Encoder, we know that it takes about 300 characters for the result. As a result we need two trunks to hold all the barcode string. We repeat the steps above and add another formula field barcode_trunk2.
  9. Add a text field (also called memo field) to the report. You can do this by selecting the text field from tool bar and dragging it to the report.
  10. Click on the text field to select it. From the Field Explorer, drag and drop Formula Field, barcode_trunk1 into the text field.
  11. Drag and drop barcode_trunk2 to the same text field. Crystal Reports puts {@barcode_trunk1}{@barcode_trunk2} into the text field.
  12. Format the text field with MRV DataMatrix font. To do this you can right click the text field and select format text... to pop up the format property sheet.
  13. Click on the Preview tab. The bar code should appear immediately. We have successfully build a report with barcode in minutes! If you are using the trial version, a dialog will pop up to remind you that you are using a trial version of the software, and all barcodes contain additional text DEMO when scanned. This limitation will go away once you purchase the retail version.