dLSoft  barcode & labelling software     

Generating barcodes in Visual FoxPro

Shows how to include Barcodes in Visual FoxPro 9 forms and reports either as picture barcodes or font barcodes.

On this page we describe the picture barcode method, which applies to:
dLSoft Active Barcode Components
dLSoft dBarcode Developer Kit

Barcodes on Visual FoxPro Forms

The Active Barcode Component products and the controls in the dBarcode Developer Kit may be added to VFP Forms in the same way as any other Active-X control.

Placing the control on the form

From the Form Controls toolbar select the "Active-X Control (OleControl)" icon.
Using the mouse with the left-button down draw a rectangle on the form where you wish the barcode to appear.
Release the mouse button and the Insert Object dialog appears.
Select the control you wish to use from the list of available controls and push the OK button.
Right-click on the control on the form and select Properties from the pop-up menu.
Locate the ControlSource property and set it to the desired data source (eg. table1.barcodedata)

Most other properties may be more conveniently set by right-clicking on the control and selecting "dLSoft Barcode COntrol object"....."Properties" from the pop-up menu; this results in the display of the control property parges.

Barcode image displayed on a Visual FoxPro 9 form


Barcodes on Visual FoxPro reports

First add a field to a table to hold the barocde image - so give it a suitable name, such as "barcode".
Set the field type to General

Placing the control on the report

From the Report Controls Toolbar select the icon for "Picture/OLE bound control"
Using the mouse with the left-button down draw a rectangle on the report where you wish the barcode to appear.
Release the mouse button and the Properties dialog appears.
set the Control source type to "General field name"
set the Control source to the field you created above (eg table1.barcode)
Click on OK to close the Properties dialog.

Adding the code

Right click on whitespace on the report
Select Data Environment from the pop-up menu - the Data Environment dialog appears.
Right click on the dialog's background and select Code from the pop-up menu.
A coding window appears.
Select the BeforeOpenTables procedure in the drop-down list at the top of the window.

Enter the following code into this window, being sure to set the ControlSource to the name you have chosen for the field in the table that holds the image, and being sure that you have used to CLASS name relevant to the product you are using (see below).

tfrm = createobject("Form")
with tfrm
.BarcodeCtrl.ControlSource = "table1.barcode"
scan all
APPEND GENERAL table1.barcode CLASS ("DLS2D4.A2barcodeCtrl.7")
&& specify the properties for this barcode
.BarcodeCtrl.Object.FixSize = -1
.BarcodeCtrl.Object.CodeType = 4
.BarcodeCtrl.Object.Xunit = 40
go top in table1
release tfrm

You also need to set the .BarcodeCtrl.Object.*** properties to values that are appropriate for the component you are using and the barcode type you wish to generate. In the above example the Caption property is shown set to table.barcodedata.

CLASS names for relevant components:

Component     CLASS name
Active Barcode component Universal (2D)    A2BARCODE.A2barcodeCtrl.4
Active Barcode component Universal (1D)    Axbarcode.Control.4
Active Barcode component Aztec    ABCAZT.AbcaztCtrl.4
Active Barcode component Databar    ABCRSS.AbcrssCtrl.4
Active Barcode component Datamatrix    ABCDMAT.AbcdmatCtrl.4
Active Barcode component PDF417    ABCPDF.AbcpdfCtrl.4
Active Barcode component QR Code    ABCQR.AbcqrCtrl.4
Active Barcode component Standard    ABC39.Abc39Ctrl.4
Active Barcode component GS1    ABCEAN.AbceanCtrl.4
dBarcode Developer Kit (1D)    abcdl7.Control
dBarcode Developer Kit (2D)    DLS2D4.A2barcodeCtrl.7

Barcode image on a Visual FoxPro 9 report

VFP Report screenshot