A few months ago, I worked on a support case where we needed to add a barcode to a Sales Order Processing transaction print out. We were able to achieve what we needed using Visual Basic for Applications (VBA) to handle some of the scripting for us. I have been meaning to write a blog post on how to make a customization like this for a really long time and have finally got around to it.
This post is a good follow up to the Dynamics Report Writer is the Best Report Writer in the World post by demonstrating another cool customization using Report Writer with VBA. I will even use the same style to format the post.
Note: There are a number of different types of barcodes used, this example will use a Code 128 barcode subtype C (aka 128C), however, it does include the code needed for 128A and 128B as well.
The customer wanted to use Code 128 barcodes on their SOP Packing Slips for the Item Number so they could be scanned at the warehouse before sending the order out. The customer had already purchased barcode True Type fonts from a vendor (in our case BarCodeWiz.com).
Using a barcode font is not just a matter of printing the Item Number using a different font. Barcodes have additional characters added for Quiet Zones and Check Digits (see Wiki post). There is an algorithm required to convert your string into the barcode characters which can then be displayed using the barcode font.
Luckily, the barcode font vendor had provided some example BASIC code designed to be used with Microsoft Office Excel's Visual Basic for Applications (VBA). As the VBA in Office is almost identical to the VBA in Microsoft Dynamics GP, we were able use their code with almost no changes.
So, we added a couple of blank string calculated fields to return our barcode characters to. One we left as the standard font (for testing purposes) and the other was changed to use one of the barcode fonts installed previously. Next we used the Tools menu to add the report to VBA, then selected the Item Number and the two newly added calculated fields and added them to VBA.
The screenshot below shows the calculated fields added onto the report layout.
Report Layout showing added calculated fields.
The code is quite simple. We just need to call one of the provided conversion functions and return our results to the added calculated fields.
Below is a screenshot of the resulting report. Note the additional characters added to the barcode text:
Example screen output showing populated barcode fields
The links below provide mode information on the Barcode code 128 and its subtypes as well as a link to the barcode font supplier used by this customer. The barcode functions included in the VBA code for this example were provided by BarCodeWiz.com and are used in this example with their permission.
I hope you find this example of how barcodes can be used on Dynamics GP reports useful.