dLSoft  barcode & labelling software     

Generating barcodes in Crystal Reports

Barcode Tools for Crystal Reports provides a variety of tools for creating barcodes in Crystal Reports. Barcodes can be generated and embedded within Crystal Report XI or later using the barcode servlets provided. For earlier versions of Crystal Reports either font-based barcodes created using a User Function Library, or OLE images created using the Crystal Report Design Component may be used.

Picture barcodes in Crystal Reports XI or later

Picture barcodes may be embedded into reports created with Crystal Reports XI or later. Picture barcodes may be Windows metafile (wmf) images or Portable Network Graphic (png) images. If the report is always viewed on Windows, or using Microsoft’s Internet Explorer then wmf images are recommended as these are vector graphics. If the report is to be viewed on non-windows machines or with web browsers other than Internet Explorer then png graphics should be used (because other systems and browsers do not support wmf images).

To incorporate barcodes into a report follow these simple steps:

1. Open the report to which you wish to add barcodes

2. From the edit menu choose Insert and then choose Picture. Navigate to the Barcode Tools for Crystal Reports installation directory and choose one of the dummybarcode image files, then push the Open button.
A movable rectangle appears. Position this at the point at which you wish the barcode to appear then click the left mouse button. Do not change the size of the rectangle. The rectangle containing a dummy barcode image appears on the report.

3. Right-click on the selected barcode image and choose Format Graphic from the pop-up menu that appears.

4. In the Format editor dialog that appears ensure that the Can Grow check box is checked then select the Picture tab.

5. Push the icon that appears alongside the Graphic Location label

6. The Formula Workshop dialog appears. If the Graphic Location item for your picture is not already selected, expand the entries under Formatting Formulas and select the Graphic Location item.

7. In the formula space enter the first part of the formula, such as
"http://localhost/dlbc/dlbc.aspx?CodeType=9&ImageHeight=12&Xunit=12&MarginSize=4&Data="+
including the quotation marks and the + sign at the end. Click once just after the + sign to ensure that the insertion point cursor is flashing.
The last item within the quotation marks is "Data=" which is pointing to the data that will be used to create the barcode.
Expand the Report Fields tree and locate the field you wish to use as the data source (the Customer.Postal Code field in this example). Double-click on the field name and the name (complete with braces) will be copied to the end of the formula.

8. Push the Save and Close button, then push OK button in the Format Editor to return to the main window in Design view.
Switch to Preview and the report complete with barcodes will be visible

Font barcodes in Crystal Report 8 or later

Barcodes in Crystal Reports may also be created using one of the UFLs (User Function Library) provided in Barcode Tools for Crystal Reports.

To create your own barcodes on a report follow the steps below:

1. Open the report in Design view

2. Select Template Field Object from the Insert menu, then place the object on the report. Resize as required.

3. Right click on the object and choose Format Template Field. Check the checkbox labeled Can Grow
Select the Font tab from the Format Editor dialog and select a suitable font, such as UNCW 24 point. Then push the OK button

4. With the Field Object selected, from the Report menu select Formula Workshop.
Expand the Formula Fields list and double click on the field you have inserted.

5. From the list of Functions (normally the middle list) scroll down to the Additional Functions item; the expand this item by clicking on the + symbol alongside the Additional Items name. Expand the Visual Basic UFLs item.

6. Select the DL1DD1UflBC function from the list, then either double click on it or press the Enter key; the function then appears in the formula box below the lists, complete with its parameter brackets and commas, and the cursor in the position of the first parameter. ie.

DL1DD1UflBC (,,)

7. The first parameter must be a string containing the barcode data. This can be a literal string (ie. data enclosed in quotation marks, such as "1234"), or field data. If field data is to be used it must be text data - so if the required field actually contains numeric data this must be converted into text data.

If a required data field contains text data just double click on the field name in the list of Report Fields, and the field name enclosed in curly brackets will be copied to the function's first parameter position. eg.

DL1DD1UflBC ({Customer.Region},,)

If a required field contains numeric data then expand the Strings item in the list of functions and the expand the ToText function; Now select the required function - which will usually be ToText(x,y,z) where the x represent the number to be used as data, y represent the number of decimal places (typically 0) and z is a character used to separate thousands from hundreds etc (which unfortunately defaults to a comma and is generally not wanted in a barcode). Double click on the required version of the ToText function and this will be copied to the first parameter position of the DL1DD1UflBC function, with the cursor now placed in the first parameter position of the ToText function, ie.

DL1DD1UflBC (ToText (, , ),,)

Now double click on the required data source field in the list of Report fields, eg.

DL1DD1UflBC (ToText ({Orders.Order ID}, , ),,)

and fill in the other two ToText parameters with a 0 (the number of decimal places) and a NULL character (two single quotes) respectively, ie.

DL1DD1UflBC (ToText ({Orders.Order ID},0 ,'' ),,)

8. Now complete the other two DL1DD1UflBC parameters with the barcode type code - 8 is for Code 128 (see the Barcode types tables in the Help file for a complete list of these) and a 0, eg.

DL1DD1UflBC (ToText ({Orders.Order ID},0 ,''),8,0)

9. Now click on the Save and Close icon to return to the Report.

10. Finally select the barcode object, right click on it, choose Format Field from the drop down menu, and click on the Font tab in the displayed dialog box. The character spacing must be left at 0, otherwise the barcodes will look nice but won't scan. Then click on OK.

11. Return to the report's Preview display and you should have a perfect barcode. If you are using data from a database as the data source for the barcode, then the barcode will change as you navigate around the record source.