ActiveReports Barcode Tutorial & FAQ
This IDAutomation tutorial focuses on helping Data Dynamics users to add barcodes to ActiveReports. Following are three popular methods of creating barcodes in ActiveReports:- Self-Checking Fonts: Best for creating Code 39 barcodes in ActiveReports.
- Fonts with a Visual Basic Module: Best for barcodes that do require a check-digit.
- ActiveX Controls: Best for creating complex barcodes such as UCC-128, EAN-128, PDF417, Data Matrix and MaxiCode.
Using Self-Checking Fonts in ActiveReports
For self-checking fonts such as Code 39, insert an asterisk (*) before and after the data to be encoded. For example, when encoding 1234567890 in a barcode, the encoded data display will be *1234567890* prior to applying the Code 39 font.
- Purchase, download and install the Code 39 Barcode Font Advantage Package.
- Start Visual Basic and open the ActiveReport that requires the barcode.
- On the ActiveReport toolbox, choose the TextBox control and
create a text box on the report that is large enough to contain
the barcode. Make a note of the name; in this case it is Field1.
- Double-click on a blank area in the report to show the report code.
- Add the following code to the report where Field1 is
the name of the TextBox that will contain the barcode, NumberData
is the field from the database needed to include in the barcode
and DAODataControl1 is the data control.
Private Sub ActiveReport_FetchData(EOF As Boolean) If DAODataControl1.Recordset.EOF Then Exit Sub Field1.Text = "*" & DAODataControl1.Recordset("NumberData") & "*" End Sub
- Run the ActiveReport to make sure the asterisk is at
the beginning and end of the data retrieved from the data
source.
- Edit the ActiveReport and change the font of the field
to contain the Code 39 fonts, then run the report again. A
barcode should appear as follows:
- With the Code 39 barcode font, tabs may be easily added between
two fields in a single barcode (in
extended39) for example:
=("*"&[DataField1] & "$I" &[DataField2] & "*")
Using Fonts with a Visual Basic Module in ActiveReports
Barcode fonts such as UPC, Code 128, Interleaved 2 of 5 and others require calculations to be performed to determine the check character. To make this calculation easier, IDAutomation provides a Visual Basic project module with purchased barcode font packages and the functions of this module may be used in an ActiveReport. In this example, a UCC/EAN-128 barcode will be added to a report. For a list of functions included in the module, refer to the Barcode Macros and VBA Functions page.
- Install the IDAutomation barcode font package of your choice. IDAutomation recommends the Code 128 Fonts because the package includes several fonts in different heights, and it encodes all letters and numbers.
- Start Visual Basic and open the ActiveReport.
- In Visual Basic, Choose Project - Add Module.
- Select the IDAutomationVBA.bas file.
- On the ActiveReport toolbox, choose the TextBox control and
create a text box on the report that is large enough to contain
the barcode. In this example, the "Human Readable" text below the
barcode will be included as required for UCC/EAN-128 specifications.
To add "Human Readable" text, simply add another field and place
it on the form. Make a note of the field names; in this case they
are Field1 and Field2.
- Double-click on a blank area in the report to show the report code.
- Add the following code to the report where Code128( )
is the function, Field1 is the name of the TextBox that will
contain the barcode, NumberData is the field from the database
to include in the bar code and DAODataControl1 is the data control. For a
list of functions included in the module, refer to the
Barcode Macros and VBA
Functions page.
Private Sub ActiveReport_FetchData(EOF As Boolean) If DAODataControl1.Recordset.EOF Then Exit Sub Field1.Text = Code128(DAODataControl1.Recordset("ucc128"), 0) Field2.Text = Code128(DAODataControl1.Recordset("ucc128"), 1) End Sub
- Run the report to confirm the data is pulls from the
fields and is properly formatted to the barcode font. There should
be some characters that have been appended to the beginning
and ending of the data from the fields. Sometimes
the data has to be formatted so much that it appears scrambled, and this is normal for Code 128 and Interleaved 2 of 5 when numbers
need to be compressed within the barcode. In the graphic below,
the first string is produced by the
Code128(DAODataControl1.Recordset("ucc128"),
0) formula and the second one is produced by the
Code128(DAODataControl1.Recordset("ucc128"),
1) formula.
- Edit the ActiveReport and change the field font to the appropriate barcode font. This method uses the IDAutomationC128M font to create a Code-128 barcode.
- When the ActiveReport is run, there will be a barcode created
in the field1 text box.
- Multiple fields may be included in a single barcode by changing
the field formula. For example, to include two fields (sscc18 and
ucc128) in a single code 128 barcode with a tab function between
them use the following formula:
Field1.Text = Code128(DAODataControl1.Recordset("sscc18") & Chr(9) & DAODataControl1.Recordset("ucc128"), 0)
Use Chr(9) for a tab and Chr(13) for a return.
Using The ActiveX Control & DLL in ActiveReports
The IDAutomation ActiveX Control and DLL may be easily used in ActiveReports. Linear barcode symbologies are available as well as 2D barcodes such as PDF417, Data Matrix and Maxicode. In the example below, a Code 128 barcode will be included in an ActiveReport. The ActiveX Control is very useful in ActiveReports because the control automatically formats "Human Readable" data for AIs in UCC128 and EAN128 barcode types.
- Purchase, download and install the ActiveX Barcode Control.
- Start Visual Basic and open the ActiveReport to add the barcode.
- On the ActiveReport toolbox, choose the More Controls icon:
- Select the barcode control from the list of available ActiveX
Controls that begins with IDAutomation and the
barcode control will appear in the report. The control may be sized
as necessary.
- To change properties of the control such as height and barcode type, select the control and choose View - Properties Window.
- To connect the control to a single data field
from the data source, select or enter the DataField property from
the property window.
- To include multiple fields in the same barcode:
- In this example, two fields (sscc18 and ucc128) are included in a single Code 128 barcode with a tab function between them. When scanned, the scanner will read the tab function which will advance the cursor to another field. This is very useful when populating multiple fields from the scanned data. Usually, PDF417 or DataMatrix is used in this situation because these 2D barcodes may encode hundreds of characters in a single symbol. Functions may only be encoded between fields in Code 39, Code 128, PDF417, Data Matrix and Maxicode barcodes.
- Make sure the barcode control is not bound to a data field and that the DataField property is blank.
- Double-click on a blank area in the report to show the report code.
- Add the following code to the report where "sscc18" and
"ucc128" are fields to be include in the barcode and DAODataControl1
is the data control.
Private Sub ActiveReport_FetchData(EOF As Boolean) If DAODataControl1.Recordset.EOF Then Exit Sub BarCode1.DataToEncode = DAODataControl1.Recordset("sscc18") & Chr(9) & DAODataControl1.Recordset("ucc128") End Sub
- Use Chr(9) for a tab and Chr(13) for a return.
- When the ActiveReport is run, the barcode will be created.