TEC-IT
TECIT
Create QR-Code!

FAQ: TBarCode OCX

FAQ TBarCode OCX and TBarCode Office: Encoding, Programming, Visual Basic, MS Access, Navision, Visual C++, PHP, Java, Barcode Output and more...

 

Word, Excel

Barcode Settings Lost After Reopening Document

Important note for Microsoft Office users: After performing the Microsoft security update from June 9, 2010 barcode objects embedded in Word and Excel documents (TBarCode OCX) may lose their settings:

Security Update for Microsoft Office Word 2003 (KB982134) + Word 2007 (KB982135)
Security Update für Microsoft Office Word 2003 (KB2251399) + Word 2007 (KB2251419)

TBarCode OCX loses barcode settings when opening or saving documents in Word 97-2003 format. Note: The problem does not appear with Word 2007 format (*.docx).

Security Update for Microsoft Office Excel 2003 (KB982133) + Excel 2007 (KB982308)

After opening or saving Excel files in Excel 97-2003 format, TBarCode OCX can no longer be edited or programmed. Note: The problem does not appear with Excel 2007 format (*.xlsx).

Microsoft Access is not affected by this problem, further Office 2003 or 2007 programs can be impaired (details see MS 10-036).

Workaround

As intermediate workaround (to gain time in production critical applications) you can uninstall the above listed security updates (see KB numbers) at your own risk.

Remedies:

  • TBarCode V9 users should update to TBarCode SDK V9.3.7 immediately: Update free of charge - download here. After updating please verify your barcodes and save the document!
  • Users of Microsoft Office 2007 (Word, Excel) may want to update to TBarCode Office V10.1 (download here).
  • Users of previous versions of TBarCode should update to TBarCode SDK V9.3.7 or alternatively to the upcoming version TBarCode SDK V10 (release in short, pre-release on request).

In case of update questions or for technical information please contact us.

Data Matrix

How to Generate an EAN Data Matrix / GS1 Data Matrix?

  • Adjust Data Matrix as symbology
  • Set the Data Matrix format parameter to EAN ( enumeration eDMPr_UCCEAN). This inserts an FNC1 on the first position in the barcode and marks the barcode as GS1/EAN type.
  • Enable Escape Sequences
  • Use the sequence \F to encode an FNC1 separator character between variable length AIs.

DP Premiumadress

How To Encode Hexadecimal Sequences as Binary Values?

TBarCode V8-V9

For encoding Hex values with TBarCode V9 you have to use "Escape Sequences" in the format "\xhh" (hh=Hex value). It is necessary to convert the hex sequence (e.g. from DP Premiumadress) into this format and turn on the TBarCode property "EscapeSequences". Below we provide VBA sample code for this conversion:

' CreateTBCHEXString(sHexValue)
' sHexValue .... Converted data stream
' sets "\x" before each byte

Private Function CreateTBCHEXString(sHexValue)
    Dim sTBCText As String
   
    'set the prefix needed by TBarCode "\xhh"
    sHexPrefix = "\x"
    
    'bring the generated string into "\xhh" format
    For i = 1 To Len(sHexValue) Step 2
        sTBCText = sTBCText & sHexPrefix & Mid$(sHexValue, i, 2)
    Next i
    
    CreateTBCHEXString = sTBCText
End Function

How To Encode Binary Data (2D Codes)

Even if you use an escape sequence for binary data the encoder will use Codepage Conversion (example: \x88 leads to a different value in Data Matrix as desired).

Solution:

  • Switch off codepage conversion (use Encoding Mode LowByte)
  • Force binary encoding mode if available (see PDF417 Encoding Mode, Data Matrix EnforceBinaryEncoding)
Relevant for DP Premium Address and other applications where you encode binary data in a 2D symbol (Data Matrix etc).

Word Plug In

TBarCode V9 Word Plug-In Not Visible in Word 2007

The following workaround can help to solve the problem with the disappearing toolbar (TBarCode V9!) in Word 2007:

  • Close Word 2007.
  • Rename or delete the following file:
  • File: "TBarCode Add-In.dot"
    Path (Windows XP): C:\Documents and Settings\[YourUserName]\Local
    Settings\Application Data\TEC-IT\TBarCode9 
    Path (Windows Vista): C:\users\[YourUserName]\AppData\Local\TEC-IT\TBarCode9
  • Start Word 2007.

By doing so, a new .dot file should be created and the plugin should be visible again.

For exploring application data you may have to enable "Show hidden files and folders" in Windows Explorer folder options.

Human Readable Text Rotation

Human Readable Text is not Rotated with Barcode

This occurs if the currently selected font does not support rotation. Select a TrueType font to solve the problem (e. g. Arial).

Human Readable Text Font

StdFont OLE object

Change Font in Microsoft Visual Basic, Visual C++, VBscript, PHP

Visual Basic

Dim fnt As stdole.StdFont
Set fnt = new stdole.StdFont
fnt.Name = "Arial"
Set TBC.Font = fnt

Microsoft Visual C++

COleFont cOF = m_TBarCode.GetFont();
tagCY cy = cOF.GetSize();
cOF.SetName("Arial"); // Font Family = Arial
cy.int64 = cy.int64 * 1.5; // add 50% to original size
cOF.SetSize(cy);
m_TBarCode.SetFont((LPDISPATCH) cOF);
cOF.ReleaseDispatch();

VBscript® (ASP):

Dim fnt
set fnt = Server.CreateObject("StdFont")
fnt.name = "Arial"
set TBC.Font = fnt

PHP (Windows):

$bcobj = new COM("TBarCode9.TBarCode9");
$fntobj = new COM("StdFont");
$fntobj->Name="Times";
$fntobj->Size=12;
$bcobj->Font=$fntobj;

Human Readable Text Font

How to Change the Font in Navision / Dynamics NAV

You need to generate an Automation Variable of type OLE Automation.StdFont. This font object is then assigned to the TBarCode COM object.

Name      Data type       Subtype
StdFont   Automation    'OLE Automation'.StdFont
    CLEAR(BC);
    BC.Refresh;
    IF ISCLEAR(StdFont) THEN
      CREATE(StdFont);
    StdFont.Size := 30;
    StdFont.Name := 'Arial';
    BC.Font      := StdFont;

Word Mail Merge

How can I Create Mail Merge Documents with Barcodes in Word?

TBarCode Office V10

Create a mail merge document with a data source. Insert a bar code into the document. Use the button "Insert Merge Field" to insert a mail merge field into the barcode.

TBarCode V9

For inserting multiple barcodes you can use the Serial Letter function in the TBarCode Word Toolbar. This function allows you to replace marked text with barcodes after the mail merge document was created. For more information about the TBarCode Toolbar and its functionality, please refer to the TBarCode OCX User Manual.

If you encounter speed problems you may alternatively use the Word Mail Merge Macro which can be downloaded in the TBarCode Download Area. The required steps for using the macro are explained in the enclosed text document.

Printing Problems

Distorted Barcode Output, Black Bar at the Top

If this occurs during printing, this effect is caused by the printer driver. Along other printer models this effect happens with Toshiba TEC and DataMax printers.

If this occurs during bitmap generation, this effect is caused by the screen driver.

The solution is to change the draw mode of TBarCode:

TBarCode V8+

Set the ActiveX Property DrawMode to Compatible.

TBarCode V7

  1. Create a file barcode.ini with the following content:
  2. [DRAW_MODE]
    UseGDIRect=1
  3. Copy the barcode.ini file to the installation directory of TBarCode (where you can find the file tbarcode7.ocx or tbarcode7.dll).
  4. Restart the program.

Reporting

Bar Codes in Microsoft Access

The common method to print bar codes from within Microsoft® Access is by using a report. The TBarCode Object need only be inserted once at the report definition. Therefore you need a table (query) which servers as data source for the report and a data field, that specifies the content of the bar code.

How to insert TBarCode OCX (as ActiveX Control) in a report?

Open a new report in design view. If you need a bar code for each record, then insert the ActiveX® Control into the detail area and position it at the desired place.

Thereto you choose Insert - ActiveX Control in the main menu. You will see a list of all available elements, from which you select TBarCode.

The control will be inserted in the detail area. The detail area will be printed once for each record set in the table (or query).

How to control the content of the bar code in a report?

In design mode right-click the TBarCode - ActiveX® Control. You will see a menu where you select Properties.

In the field Control Source located in the sub menu data you can define the content of the control. That means you can select the table or query field which is encoded as bar code.

Microsoft Access

Truncated Bar Codes in Microsoft Access

Depending on the printer driver the first bar in the symbol may be truncated (when printing through Microsoft Access). Also the symbol may be shifted inside of the bounding box.

If this occurs you can work around this problem by specifying an additional quiet zone around the bar code. This can be done in the property tab Appearance - Quietzone - Adjust.

If you have specified a module width, please make sure that the bounding box is large enough to display the bar code without clipping.

Visual Basic

Runtime Error '429': ActiveX component can't create object

You may get this runtime error if you didn't specify the full Prog-ID with CreateObject. Reference the TBarCode Type Lib in the project settings, and use the following commands to create a TBarCode object in VB (sample for TBarCode OCX V9):

      Dim objTB As TBarCode9
      Set objTB = CreateObject("TBarCode9.TBarCode9")
      objTB.AboutBox

For further trouble shooting read Microsoft Knowledge Base Article - 244264

COM and Java

How can I use your ActiveX Control in JAVA?

ActiveX Controls are COM based so they can be treated as objects. If you have a bridge between Java and ActiveX you can easily integrate TBarCode OCX into your Java projects.

We recommend to try out OLEJA, which is a tool to create Java components from COM components. Here is the link to the product page: www.simtel.net

Another possibility is the open source toolkit JAWIN API: www.develop.com

(Please note that TEC-IT can not offer support for third party products).

Barcode Fonts

Why Should I Use TBarCode Instead of a Bar Code Font?

Adjustable PropertyTBarCodeBarcode Font
Adjusting or optimizing the bar width gives you better barcode quality results
Module Width
yesno
Print Ratiofreely scalablemaintain a special height / width ratio
Rotation 0°, 90°, 180°, 270°yesnot always

Licensing with Excel

Microsoft Excel - Licensing during Open

Licensing happens during startup of the document which contains the ActiveX® Control.

  • Open the Microsoft VBA editor with Alt+F11.
  • In the Project Explorer select This Workbook.
  • Now enter the following code as for the Workbook-Open Event (sample for TBarCode OCX V9):
  • Private Sub Workbook_Open()
     Dim tbc As TBarCode9
     Set tbc = CreateObject ("TBarCode9.TBarCode9")
     tbc.LicenseMe "Mem:Licensee", eLicKindDeveloper, 1, "Key", eLicProd1D
     Set tbc = Nothing
    End Sub

We recommend to password protect your VBA code in the project property window.

Product Licensing with Access

Microsoft Access - Licensing with Autoexec Macro

Below we show you how to license at startup of the database (sample for TBarCode OCX V9). Create a new Module with the following function (in Microsoft VBA Editor):

Public Function LicenseTBarCode()
 Dim TB As New TBarCode9
 TB.LicenseMe "Mem:Licensee", eLicKindDeveloper, 1, "Key", eLicProd1D
 SetTB = Nothing
End Function

Create a new Macro named "Autoexec" with the following settings:

Action = RunCode
Functionname = License TBarCode()
Don't forget to include a reference to the type library of the ActiveX® Control in the menu Tools - References (otherwise enumerations cannot be used). We recommend to password protect your VBA code in the project property window.

PDF417

How Can I Generate an Optimized PDF417 Bitmap Image?


Please use this code snippet as starting point:

Barcode.Barcode = eBC_PDF417
Barcode.Text = "My Data... "

' the following settings produce a barcode 82,296 mm wide
' if your barcode should have a constant width, set the data columns
' as shown below (increase/decrease to make wider/smaller symbol)

Barcode.PDF417.Columns = 15

Dim X, Y
Dim Scaling
Dim Dpi

' define ratio of module width (small bar width) to row height
X = 1
Y = 1       ' keeps default ratio, which is 1:3
'Y = 3 / 2  ' creates 1:5 ratio

Dpi = 300     ' 300 dpi printer
Scaling = 3   ' 1 Module (smallest bar) = 3 Pixels = 0.254mm

Dim Cols
Dim Rows

Cols = Barcode.Get2DXCols()
Rows = Barcode.Get2DXRows()

Dim XSize
Dim YSize

XSize = Int(X * Cols)     
YSize = Int(Y * Rows)   

' scale with DPI enlarging factor
XSize = XSize * Scaling
YSize = YSize * Scaling

' Save barcode as bitmap
Barcode.SaveImage "c:\temp\barcode.bmp", eIMBmp, XSize, YSize, Dpi, Dpi

PDF417 in Access VBA

How can I Generate a PDF417 in Access VBA?


Please use this code snippet as starting point:

' set barcode type = PDF417
Me.bc.Object.BarCode = 55

' set size mode to CustomModuleWidth
Me.bc.Object.SizeMode = 1

' now adjust module width to 0.254 mms
Me.bc.Object.ModuleWidth = "254"

' set number of data columns
' optional parameter, but required to get constant width
Me.bc.Object.PDF417.Columns = 5

' adjust row height to 3 times of the module width
Me.bc.Object.PDF417.RowHeight = 254 * 3

Me.bc.Object.Text = "my data"

TBarCode OCX with Word 2003

I Cannot Protect my Word Documents!

Since I've added TBarCode to my Word 2003 document, I cannot protect it.

Solution: You have to leave design mode to be able to protect the document. If you insert a Barcode Control, the document is switched to design mode. Through the Control Toolbox you can leave design mode, then you are able to protect the document.

For further information visit Microsoft Office Online.

Excel VBA

How can I Generate a Data Matrix in Excel VBA with CopyToClipboard?

Please use this code snippet as starting point.

Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long)  As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long

Dim obj As New TBarCode9
Dim nWidth As Long
Dim nHeight As Long
Dim dc As Long

  With obj
    .BarCode = eBC_DataMatrix
    .DataMatrix.Size = eDMSz_32x32
    .Text = myData

    .QuietZoneUnit = eMUModules
    .QuietZoneBottom = 2
    .QuietZoneLeft = 2
    .QuietZoneTop = 2
    .QuietZoneRight = 2

    .ModuleWidth = "508"
    .SizeMode = eSizeMode_CustomModuleWidth
    .Dpi = 1440 / Screen.TwipsPerPixelX ' screen resolution in dpi

    dc = CreateCompatibleDC(0) ' screen DC

    nWidth = .BCWidthHdc(dc, 96, 96, eMUPixel) ' module width should be set
    nHeight = .BCHeightHdc(dc, 96, 96, eMUPixel) ' module width should be set
   
    .CopyToClipboardEx dc, nWidth, nHeight, ""

    DeleteDC(dc)
  End With

ISO-8859-15, GLI, ECI

How can I encode char set ISO-8859-15 into PDF417?

TBarCode V9 and Barcode Studio V9 allows you to specify the target code page for the data to be encoded.

tbarcode.CodePage = eCodePage_Custom
tbarcode.CodePageCustom = 28605   ' Latin-9 on Windows

Alternatively you can use Windows API character set conversion functions.

The PDF417 "GLI" code is an indicator for the reader software, which character set is used for the forthcoming data string. The AIM ECI table contains ECI 000017 for ISO/IEC 8859-15 Latin alphabet No. 9. ECI is the successor of GLI.

The GLI or ECI indicator does not automatically convert the data to the required character set! Consider that GLI or ECI code words are not always supported by the reading software.

The GLI or ECI indicator can be insert by escape sequences into the data stream:

PDF417: \Gnnnnnn (n...6 digits specifying the GLI)

Encode: \G000017 + bar code data
If you use escape sequences, make sure that translation of escape sequences has been enabled in the barcode generator.

FNC1 With GS1 Barcodes

How To Encode FNC1 (GS1 Barcodes)?

What is the meaning of FNC1?

FNC1 is used as a field separator for variable length application identifiers (AIs) and is encoded by the sequence \F. For instance, the batch number is a variable length data field and needs an FNC1 as terminator if the data length is lower than the maximum of 20 characters.

Please note:

  • For encoding the FNC1 you have to activate Translate Escape Sequences.
  • Do not use FNC1 after the last data field.
  • Do not use FNC1 if the maximal field length is used.

Example 1: FNC1 with TBarCode

In the following examples we generate a GS1-128 bar code with two application identifiers (AIs): The charge number (AI =10, variable length, needs FNC1) and the expiration date (AI=15).

' set the barcode type = GS1-128 (EAN/UCC 128)
TBarCode91.BarCode = eBC_GS1_128
' enable Translate Escape Sequences
TBarCode91.EscapeSequences = True
' set the data to be encoded
TBarCode91.Text = "10222333\F15100701"

Example 2: FNC1 with Barcode Studio

For demonstrating on how it works with Barcode Studio we use the same example data as shown in the previous code sample. Follow these steps to insert a FNC1 control into your bar code data:

  1. Enter „10222333\F15100701“ as for the bar code data.
  2. Then switch to the advanced properties tab and mark the check box Escape Sequences.
  3. FNC1 is inserted and the application identifier (AI=15) is displayed.

TBarCode SDK

How can I Adjust the Default Barcode Type?

The default bar code type can be set through a file named barcode.ini.

The barcode.ini file must be located in the installation path of TBarCode and has to contain the following lines:

[DEFAULT_SETTINGS]
BarcodeType=8

The index (in this example 8) for the required barcode type can be found in the barcode reference, chapter 6.

TBarCode x64

How to Make TBarCode Control Visible in Word, Excel, Access (Windows x64)

Microsoft Word/Excel/Access are running in 32-Bit compatibility (WOW64) mode. They are no full 64-Bit applications, but they can be still operated under Windows 7 x64.

So you need to install the "normal" TBarCode OCX 32 Bit Edition (remove your TBarCode x64 edition if you have installed it).

http://www.tec-it.com/download/TBarCode_Setup.msi

Then you should see the TBarCode Control in the Legacy Tools selection.

© TEC-IT Datenverarbeitung GmbH, Austria  ++43(0)7252/72720  office@tec-it.com