Friday, May 14, 2010

How to use barcodes in your Ax report - Part 1/2

Barcodes have been around for a long time. And despite newer technologies, they remain popular. Deservedly!
You can use barcodes in production environments, for coding your invoices, in retail, POS, ...

The programmers of Ax have made it easy for you to use them. Fonts and classes have been provided in Ax to get you up and running with barcodes quickly. In this post I'll show you how you can use barcodes in your report.

This is post 1 of 2. In this post, we'll cover the very basics. And for that, we'll use barcodes of type Code 39. Why Code 39? Because they are commonly used, read by almost every scanner and very easy to implement.

Code 39 supports alphanumeric characters, and some special characters like - . $ / + % SPACE.
Unlike with most other type of barcodes, no real encoding is needed (no check digit either). All you really have to do is set the right font. This means you can even use this barcode type easily in for example Word!
Altough Ax supports encoding of Code 39, we are not going to use it now, for reasons of simplicity. (Encoding will be dealt with in part 2 of this post.)

Let's assume we have a report in Ax, showing all our inventory items. This reports uses InventTable as a base.
We would like the barcode to consist of the ItemId. For that purpose, we create a display method, like this:

Display str ShowBarcode()
return "*"+strupr(InventTable.ItemId)+"*";

The asterisk (*) is the start and stop character in Code 39, that's why we add it.
We add this display method to the body of our report.
Next up, we set the appropriate font for our report control.

Make sure you set the width of the report control big enough! (Make it center aligned as well.)

And that's all there is to it. Have a look at the result, as seen in our print preview:

Note that the readible text below the barcode is printed with a separate report control. It's not included with the actual barcode.

The main drawback with Code 39 is the length of the barcode. They use up quit some space on your reports, where as the available space may be limited on some occasions (small labels).

Look out for part 2 of this post, with encoding of Code 128, a more dense code.


  1. Hi.

    Good article.

    We are using barcodes with some difficulties, we want to use barcodes but vertically, do you know how to accomplish this with AX?


  2. Hi there,

    Thanx for the comment.
    Good question, so I decided to dedicate a separate blog post to it. Read about it