BarCodeWiz Logo

Data Matrix 2D Barcodes in MS Access Query

Easily Encode Data Matrix Barcodes in Access Query

  • This tutorial shows how to encode the barcode value directly in a SQL query.
  • The query is based on a data table. It has all the same fields as the table, plus one barcode field.
  • The benefit of this method is the query can be used as data source to an Access Report, Form, or even other programs like MS Word or Publisher.
  • Any software which imports from an Access database can create Data Matrix barcodes.

Step 1. Import module with barcode functions

  • Click on Database Tools tab > Visual Basic (or press Alt + F11).
Open the Visual Basic Editor in Access to import BarCodeWiz Data Matrix module

  • Right-click the database and Import File....
Import of BarCodeWiz Code128 module into access file

  • Select BarCodeWizDataMatrix.bas.
  • The default location of the file is:
    Program Files\BarCodeWiz\BarCodeWiz Data Matrix Fonts\BarCodeWizDataMatrix.bas
Select BarCodeWizDataMatrix.bas to import module into your project

  • The following module should now be part of the Access file.
Preview of DataMatrixEncode function after importing to Access

Step 2. Create a new table (or use an existing table)

  • Create a new table or use an existing table. Our table has the following data:
  • item_barcode is a Text field containing the barcode data we will encode.
  • item_name is a Text field with item description
  • item_price is a Number field with the item's price
Preview of the table with to encode to Data Matrix barcodes

Step 3. Create a new Query

  • Click on Create tab > Query Design
Go to CREATE and then click on Query design to begin designing the query with Data Matrix barcode in it

Step 4. Add our table to the query

  • Click on Query Design and select Add Tables
Add Tables Button

  • Double-click on Items in the Add Table dialog, and click Close.
Click on Items in the Add Table dialog to add the table to a query with Data Matrix barcode in it

Step 5. Edit Query

  • Add all items in the first column: Items.*
  • Add a new calculated field to show the encoded barcode:
    MyBarcode: DataMatrixEncode([item_sku])
Edit the query with Data Matrix barcode

Step 6. Save the Query and preview

  • The field MyBarcode contains the encoded value of item_barcode. The function DataMatrixEncode() encodes the text into Data Matrix barcode.
  • This query may be used anywhere you'd normally use the Items table.
  • To display it as a barcode, simply change the Font Name and Size in the Report.
Preview of the query with data in it

EXAMPLE: Using the query as a data source for a Report

  • Create a new report: Create > Report Wizard
Click on REPORT WIZARD to use your query as a source for the report

  • Select the ItemsQuery as the source and select all fields.
  • Click Finish and edit the report in Design Mode.
Using the REPORT WIZARD to create report with Data Matrix barcode in it

  • Switch your report to Design View, by right-clicking it and selecting "Design View".
  • Edit the text box  (right - click on the text box and select: "Properties") to change the Font Name and Size:
    Font Name: BCW_DM
    Font Size: 10
  •  Set "Can grow" to Yes.
  • It may be necessary to make the column with barcode a bit wider.

NOTE:  For smaller barcodes, you can set the point size as low as 2pt

Setting the properties of TextBox  so that Data Matrix Barcode was displayed properly.

Ready

  • Print Preview of the report.
Preview of the report with Data Matrix barcodes