Chapter 7. Adding DataMatrix to Microsoft Office Documents

7.1. Access (ActiveX Control)

This section explains the steps to add DataMatrix barcodes in a Microsoft Access report using Morovia DataMatrix ActiveX Control.

  1. The DataMatrix ActiveX control must be installed and registered on the computer.

  2. Open a report in design view and choose InsertActiveX Control.... If you are using Access 2007 or 2010, switch to Design view, and click on Insert ActiveX Control button.

  3. From the list of controls, select Morovia DataMatrixControl.

  4. After the control is placed on the report, right click on it and choose Properties...

  5. Modify the Control Source property to point to the table and field of the data you wish to encode into the barcode. The data source can be a table field, or a field of a comprehensive query result.

  6. Modify other properties, such as ModuleWidth, and SizeID. After you are satisfied with the result, close the property dialog.

  7. Save the run the report. You should see the barcodes appear in the report.

7.2. Access (using DataMatrix Font)

You can also add DataMatrix barcodes to Access report using font-based solution.

  1. Before creating barcodes in Microsoft Access, you must import the required module. This module adds VBA function so that you can put into the report. Choose ModulesImport and select Morovia.DataMatrixFontDLL5.bas file, located in the program folder.

  2. Open a report in design view and add a text box to the report. The text box will be modified to contain a barcode.

  3. Right click on the text box and choose properties.

  4. Place the formula =DataMatrixEncode([TestData.Data],-1) in the control source property of the text box where [TestData.data] is the field that contains the data to be encoded into the DataMatrix barcode. The following parameter is the size ID desired.

  5. Run the report. You should see lines of hexadecimal characters appear in the place of the text box. This is the barcode string in the raw text form.

  6. Go back to the design view and change the font of the text box. In our case, choose MRV DataMatrix5 and 6 points. Adjust the size of the text box to fit the whole barcode.

  7. Save and run your report. You should see the barcodes appear in the report.

7.3. Excel (ActiveX Control)

Excel has line gap issues with DataMatrix fonts. You can paste EMF image from GUI encoder, or use ActiveX control as outlined below.

  1. After you finished other parts of the spreadsheet, choose ViewToolbarsControl Toolbox

  2. When Control Toolbox appears, click on More Controls button.

    On Excel 2007 and 2010, first switch to developer tab, then press Insert button on the toolbar, and select More Controls button.

  3. From the list of controls presented, choose Morovia DataMatrixControl.

  4. Select the area to place the control in the spreadsheet.

  5. Right click on the control, choose Properties and change the Linked Cell property to the name of the cell that contains the data you wish to encode.

  6. Change other properties as necessary such as Rows, Cols and AspectRatio to adjust the size of the barcode.

  7. After editing the properties, click on Exit Design Mode button to exit design mode. The barcode will appear in the spreadsheet.

  8. The barcode is now bound to the cell. Change the data of the linked cell, the barcode will change accordingly.

    Note: to subsequently modify or delete the barcode control, Excel must enter Design Mode. This can be done by pressing the Design Mode button on the Control Toolbox.

7.4. Microsoft Word

Using Datamatrix control in Microsoft Word is similar to the one in Excel, except that Word does not provide a way for data binding.

  1. choose ViewToolbarsControl Toolbox.

  2. In the toolbox, choose the more controls button.

  3. Select Morovia DataMatrixControl from the list of available ActiveX controls. After selecting it, the control will appear in the document, the control may be sized as necessary. To change the properties of the control right click on the control and choose Properties.

  4. When finished, exit the design mode by choosing the design mode button.

  5. To edit the properties of the control the program must be in design mode. If there are problems editing the properties of the control, press the design mode button to enable it.

7.5. Word Mail Merge

This tutorial uses Excel file Word Mail Merge DataSource.xls as mail merge data source. The data looks like this:

We want to print address information as well as a DataMatrix barcode that encodes such information in Avery label paper 5163. The Print Preview looks like the one below:

  1. Before we start, we need to import a module into Excel. To do that, open Visual Basic Editor. In Excel 2007, this is done by selecting DeveloperVisual Basic.

    In Visual Basic Editor, choose FileImport File. Navigate to the DataMatrix Fonts & Encoder 5 installation folder, and select the Morovia.DataMatrixFontDLL5.bas.

    Close Visual Basic Editor.

  2. Add a new column in the spreadsheet that will hold the barcode string. In our case, we use column H. In cell H2, enter the definition as below:

    After hitting Enter, you should see a hexadecimal string result show up. If not, examine the formula you entered.

    Note the use of Excel function CONCATENATE here. This function is used to combine several fields, as well as line return characters.

    See the DLL API for the meaning of each field. Here we set size ID to -1.

  3. Copy the formula to other cells of the same column. This can be done by selecting cell H2, highlighting the cells that the formula is copied, and select Paste.

    Close the Excel file and start Microsoft Word.

  4. In Microsoft Word, choose MailingStart Mail MergeLabels. Select Avery 5163 as the label we will work on.

  5. Select Select Recipients Select Existing List. In the file dialog, navigate to the spreadsheet we just created. If it asks for Select Table, choose Sheet1$.

  6. Click on Address Block. This is for the address line. Microsoft Word has the intelligence to select the address block.

  7. Hit Enter once to move the cursor below, and click on Insert Merge Field. Select Barcode as the merge field.

    Click on Review Results. You should see the first record show up, with hexadecimal characters in the place of barcode.

  8. Now adjust the font for the address block and the barcode field. For the address block, we use Arial 16 points. For the barcode, use MRV DataMatrix5 6 points.

  9. Copy the format to other labels by selecting Update labels.

  10. Select Preview Results to view the sheets of labels.