Home Products Support Blog Contact

Generate QR Codes in Access database report

Keywords: Access 365, QR Code

With Barcodesoft QRCode Web Service, users can generate QRCode (or any other barcode symbol) in Access database report.

No download needed! No 3rd-party software installation needed!

All you need is just internet access.

When you open the sample database, it will ask you whether to enable VBA codes. Please choose Enable Content.

Please create a "c:\temp" folder in your C Drive. All dynamic generated QRCode images will be saved in this folder.

Now, please open Forms and run Form1. Click "Download" button. It will automatically download all QR Code images to your "c:\temp" folder.

QR Code image file name will be saved to the attachment field of current record.

If you run report now, you will find each record has its own QR Code.

Now, let's look at the VBA codes

    
        Option Compare Database
        Option Explicit


        ' API declarations. For 64-bit Office, Please add PtrSafe attribute. 
        ' Don't add this attribute for 32-bit Office
        Private Declare PtrSafe Function URLDownloadToFile Lib "Urlmon" Alias "URLDownloadToFileA" ( _
        ByVal pCaller As Long, _
        ByVal szURL As String, _
        ByVal szFileName As String, _
        ByVal dwReserved As Long, _
        ByVal lpfnCB As Long) _
        As Long

        ' Download a file or a page with public access from the web.
        ' Returns 0 if success, error code if not.
        '
        ' If parameter NoOverwrite is True, no download will be attempted
        ' if an existing local file exists, thus this will not be overwritten.
        '
        ' Examples:
        '
        ' Download a file:
        '   Url = "https://www.codeproject.com/script/Membership/ProfileImages/%7Ba82bcf77-ba9f-4ec3-bbb3-1d9ce15cae23%7D.jpg"
        '   FileName = "C:\Test\CodeProjectProfile.jpg"
        '   Result = DownloadFile(Url, FileName)
        '
        ' Download a page:
        '   Url = "https://www.codeproject.com/Tips/1022704/Rounding-Values-Up-Down-By-Or-To-Significant-Figur?display=Print"
        '   FileName = "C:\Test\CodeProject1022704.html"
        '   Result = DownloadFile(Url, FileName)
        '
        ' Error codes:
        ' -2146697210   "file not found".
        ' -2146697211   "domain not found".
        ' -1            "local file could not be created."
        '
        ' 2004-12-17. Gustav Brock, Cactus Data ApS, CPH.
        ' 2017-05-25. Gustav Brock, Cactus Data ApS, CPH. Added check for local file.
        ' 2017-06-05. Gustav Brock, Cactus Data ApS, CPH. Added option to no overwrite the local file.
        '
        Public Function DownloadFile( _
        ByVal Url As String, _
        ByVal LocalFileName As String, _
        Optional ByVal NoOverwrite As Boolean) _
        As Long

        Const BindFDefault  As Long = 0
        Const ErrorNone     As Long = 0
        Const ErrorNotFound As Long = -1
        Dim Result  As Long

        If NoOverwrite = True Then
        ' Page or file should not be overwritten.
        ' Check that the local file exists.
        If Dir(LocalFileName, vbNormal) <> "" Then
        ' File exists. Don't proceed.
        Exit Function
        End If
        End If

        ' Download file or page.
        ' Return success or error code.
        Result = URLDownloadToFile(0, Url & vbNullChar, LocalFileName & vbNullChar, BindFDefault, 0)

        If Result = ErrorNone Then
        ' Page or file was retrieved.
        ' Check that the local file exists.
        If Dir(LocalFileName, vbNormal) = "" Then
        Result = ErrorNotFound
        End If
        End If

        DownloadFile = Result

        End Function


        Private Sub Command1_Click()
        Dim i, rcount As Integer
        Dim dbLib As Database
        Dim rsTable1 As Recordset
        Dim Result As Long
        Dim rsAttachment As Recordset2

        Set dbLib = CurrentDb
        Set rsTable1 = dbLib.OpenRecordset("Table1")
        rcount = rsTable1.RecordCount
        For i = 1 To rcount
        With rsTable1
        rsTable1.Edit

        Set rsAttachment = rsTable1.Fields("QRCode").Value        
        'QRCode is the name of Attachment field
        If (rsAttachment.EOF) Then
        rsAttachment.AddNew
        Else
        rsAttachment.Edit
        End If

        rsTable1.Fields(5) = "https://www.barcode-soft.com/barcode.ashx?s/qrcode/text/" + rsTable1.Fields(2) + _
        " " + rsTable1.Fields(3) + " " + rsTable1.Fields(4) + "/w/200/quiet/10/token/barcodesoft"
        ' /s/qrcode specify symbol as QRCode. 
        ' You can change symbol to code39, code128b, upca, ean13, datamatrix, etc
        ' /text/rsTable1.Fields(2) specify text to encode
        ' /w/200 specify size to 200 pixels
        ' /quiet/10 specify quiet zone to be 10 pixels
        ' /token/barcodesoft  This is the token users need to call web service. 
        ' You can use it for free with a Barcodesoft logo in the image.
        ' If you want to get rid of Barcodesoft logo, please get a license.
        Result = DownloadFile(rsTable1.Fields(5), "c:\temp\" & rsTable1.Fields(1) & ".png", True)     
        ' download dynamic QRCode image to local folder c:\temp

        rsAttachment.Fields("FileName").Value = "c:\temp\" & rsTable1.Fields(1) & ".png"              
        ' Set FileName of Attachment field
        rsAttachment.Fields("FileData").LoadFromFile "c:\temp\" & rsTable1.Fields(1) & ".png"         
        ' Set FileData of Attachment field
        rsAttachment.Update
        rsTable1.Update
        '-- Go to Next Record ---
        rsTable1.MoveNext
        End With
        Next
        End Sub
    
Here is a list all all parameters of QR Code web service

Parameter Description Sample URL
Parameter Description Sample URL
s s means Symbology. It is always the first parameter for this web service. Accepted value could be one of the following:
Code39,Code39Ext, CODE128A, CODE128B, CODE128C, GS1128, UPCA, UPCE, EAN13, EAN8, Bookland,INTERLEAVED25, Code11,MSI, Code25,CODE93, Codabar,TELEPEN, Datamatrix, QRCODE, Aztec and PDF417.
Default symbology is QRCode.
http://barcode.barcodesoft.com/barcode.ashx?s/qrcode/text/ABCD1234
text string to encode. http://barcode.barcodesoft.com/barcode.ashx?s/qrcode/text/ABCD1234
token A 14-digit token for each user. If you leave it blank, or your token subscription has expired, your barcode will have a demo watermark. http://barcode.barcodesoft.com/barcode.ashx?s/qrcode/text/ABCD1234/token/xxxx
orientation barcode image orientation. Accepted value could be one of the following: left, top, right and bottom. Default value is bottom. http://barcode.barcodesoft.com/barcode.ashx?/s/qrcode/text/ABCD1234/orientation/2
format format means image format. Accepted value could be one of the following: TIFF, PNG, GIF, Jpeg, BMP. Default value is BMP. http://barcode.barcodesoft.com/barcode.ashx?s/qrcode/text/ABCD1234/format/gif
r format resolution. Accepted value could be one of the following: 96, 200, 300, 400, 500, 600. Default value is 96. http://barcode.barcodesoft.com/barcode.ashx?s/qrcode/text/ABCD1234/r/300
h barcode image height. Leave it blank for automatic height. http://barcode.barcodesoft.com/barcode.ashx?s/qrcode/text/ABCD1234/h/300
w barcode image width. QR Codes are always squares. Therefore, there is no need to specify height. http://barcode.barcodesoft.com/barcode.ashx?s/qrcode/text/ABCD1234/w/300
qe QRCode error correction level. Accepted value ranges between 1 and 4. Only available when symbology is QRCode. http://barcode.barcodesoft.com/barcode.ashx?s/qrcode/text/ABCD1234/qe/2
qs QRCode target size. Accepted value ranges between 1 and 40. When size specified is not big enough to hold all data, it will return a warning to choose the next size big enough to hold all data. http://barcode.barcodesoft.com/barcode.ashx?s/qrcode/text/ABCD1234/qs/2

Here is the pricing list of Access 365 QRCode web service.
License Small Business License Developer License 5 Developer License Unlimited Developer License
Price CAD199 (Up to 5,000 barcodes generation per month) CAD399 (Up to 30,000 barcodes generation per month) CAD599 (Up to 100,000 barcodes generation per month) CAD799 (Up to 300,000 barcodes generation per month)