Create QR Code in Crystal Reports with a UFL (User Function Library)

This tutorial illustrates the use of a UFL (User Function Library for Crystal Reports) with a True Type Font (QR Code Barcode Font), provided in ConnectCode QR Code package, to create a ISO/IEC 18004:2015 standard-compliant QR Code barcode in Crystal Reports. A User Function Library is a dynamic link library that enables Crystal Reports to add customized functions to Formula Workshop.


  • ConnectCode QR Code package is installed
  • CRUFL_QRCodeBarcode.dll in the Resource\CrystalReportsUFL subdirectory of ConnectCode QR Code package.
  • Crystal Reports 2016 (the UFL works on earlier versions as well)
  • x86 Native Tools Command Prompt
  • Administrator Rights


1. Launch Windows Explorer and go to the ConnectCode QR Code package folder. The QR Code package is installed in "C:\Program Files (x86)\ConnectCodeQRCode" folder by default.

In the "Resource\CrystalReportsUFL" subfolder, locate the "CRUFL_QRCodeBarcode.dll" and "crw32.exe.config" files, and copy the files to the Crystal Reports Library folder. The Crystal Reports Library folder is located in a folder similar to the one below.

	C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\win32_x86       

The "crw32.exe.config" file contains the following to enable mixed-mode assembly.

	<?xml version ="1.0"?>
  		<startup useLegacyV2RuntimeActivationPolicy="true" >			
    		<supportedRuntime version="v4.0" />

2. Launch the "x86 Native Tools Command Prompt for VS 2017" (the 32-bit prompt is required for loading a UFL to Crystal Reports) as Administrator from the Windows Start Menu.

3. In the Command Prompt, use the "cd" command to go to the Crystal Reports Library folder.

	cd C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\win32_x86	 

4. Enter the following command in Command Prompt to load the UFL.

	gacutil -i CRUFL_QRCodeBarcode.dll				

	Regasm CRUFL_QRCodeBarcode.dll				

Ensure that the UFL is loaded successfully as shown in the screenshot below.

5. Launch Crystal Report and create a new "Standard Report". Click on the Finish button when prompted to select the data that you want to report on.

6. When the report is created, right click on "Formula Fields" in the "Field Explorer" and select "New" to create a new formula.

7. Name the formula as "qrcode".

8. In the "Formula Workshop", expand "Functions->Additional Functions->COM and .NET UFLs (u212com.dll)". Check that you see the "ConnectCodeClassQRCodeEncode" formula. If you do not see this formula, please ensure that you have run steps 2-4 successfully.

9. Double click on the formula, change “Crystal Syntax”to “Basic Syntax” and enter the following VBA programming codes below:

	Dim x As Number
	Dim Result As String
	For x = 1 To ConnectCodeClassQRCodeNumBlocks() 
        	Result=Result + ConnectCodeClassQRCodeGetBlocks(x)		
	Next x
	formula = Result	

The formula uses "12345678" as the input data, "L" as the error correction level and 8 as the Mask.

Error Correction Level: "L" ("L", "M", "Q" or "H")

L - Allows recovery of up to 7% data loss
M - Allows recovery of up to 15% data loss
Q - Allows recovery of up to 25% data loss
H - Allows recovery of up to 30% data loss

Mask: 8 (0 to 7 or 8 for Auto)

The purpose of a mask pattern is to make the QR code easier for QR scanner to read.

After the QR Code is encoded, a loop is required to return the output in blocks. The reason is because Crystal Reports enforces a 255 characters length limit on the output returned by a UFL formula.

10. When ready, click on the "Save and close" button. In the designer, drag the "qrcode" formula onto the report.

On the Design tab, select the object created and change the font to "CCodeQR" (or "CCodeQR_Trial"). Change the Font Size to 6 to fit the barcode nicely on the report.

11. Click on "View->Print Preview" to preview the report with the QR Code barcode.