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.
Are you able to scan these barcode ? I have used barcode fonts on Report Writer to show Sales Order No but not able to scan until I added * on starting and Ending of barcode.
I don't have a barcode scanner to test with, but adding any additional characters is simple from the VBA code.
Please note that we are already calling functions to convert the Item Number into the text needed for Code 128 barcodes which is adding additional characters before and after the Item Number.
Having done a lot of work with 1 dimensional and 2 dimensional barcodes, I can say from experience that a lot of users encounter the problem with the asterisk (*) at the beginning and end of the barcode.
One of the most common problems is that applications like Microsoft Word will change the text from simply a bunch of characters with an asterisk on both sides, into a bold face set of characters. The program thinks you are trying to place emphasis on the text. With the code David is showing, this is not an issue as he is programmatically specifying the format. It’s a good example and should shed some light on just how easy it can be for a Dynamics GP system to start taking advantage of barcodes.
Also, take a look at my article RW - Working with POSTNET barcodes for US zip codes at dynamicsgpblogster.blogspot.com/.../rw-working-with-postnet-barcodes-for-us.html. This article deals with coding the zip codes using the algoritm provided by the US Postal Service.
That is another great example, thanks for highlighting it.
Mark seems to have a real dislike for Report Writer....
Posting from Mark Polino at DynamicsAccounting.net.
Maybe we should do some Advanced Report Writer at Tech Conference and Convergence... just saying!
Posting from Mohammad Daoud
PLEASE READ BEFORE POSTING
Please only post comments relating to the topic of this page.
If you wish to ask a technical question, please use the links in the links section (scroll down, on right hand side) to ask on the Newsgroups or Forums. If you ask on the Newsgroups or Forums, others in the community can respond and the answers are available for everyone in the future.