Printing different field types as bar codes

In a report, you can print any database field as an automatic bar code. See Printing bar codes in FileMaker Pro for step-by-step instructions.

Overview

To print bar codes, simply define / create a calculated field in your database table - using menu Define | Database Ctrl+Shift+D (or by clicking the Define Database on the Standard toolbar in Layout mode).

This expression calculates a Code 128 bar code for the field MyField (by using function CIA_CODE128).

CIA_CODE128( MyField )

Drag the new field to your form / report and set its Font property;

Font: CIA Code 128 Medium  
Size: 14  

Note: For each type of bar code, there is a unique function to use and an associated bar code font to select. See Bar code functions and Bar code font name and font size to use.

Any field (Text, Number, Date/Time, etc.) or any expression which evaluates to a string, can automatically print as a bar code.

Formatting database fields

Below are some useful examples that show how to format different field types, so that they are suitable parameters for bar code functions.

Text field concatenation

A typical requirement is to print bar codes containing more than one field. If OrderNumber and BatchNumber are both text fields, you can use simple string concatenation, like so;

=CIA_CODE128( OrderNumber & "," & BatchNumber )

to print a Code 128 bar code containing two fields, separated by a comma.

Date fields

When printing bar codes containing dates we often need to print dates in YYMMDD format, or YYYYMMDD.

For example, if you are in the USA and the year is 2005, the month is June and the date is the 25th the date is 25/6/2004 and the date in YYMMDD format is 040625 (and in YYYYMMDD format 20040625).

Use Let( ) to print complex expressions. Let() allows you to break complex expressions in to readable parts.

The following calculates y as the year, m as the month and d as the day of the month. Then these are formatted with leading zeros in ys, ms and ds.

If MyDateField is a field containing the data, this formula calculates a Code 128 bar code containing the data in YYYYMMDD format;

Let ( [
  y = Year ( MyDateField ); ys = y; 
  m = Month ( MyDateField ); ms = If( Length(m) = 1; "0"; "") & m; 
  d = Day ( MyDateField ); ds = If( Length(d) = 1; "0"; "") & d
];
  CIA_CODE128(ys & ms & ds)
)

And YYMMDD format;

Let ( [
  y = Year ( MyDateField ); yr = Mod ( y; 100 ); ys = If( Length(yr) = 1; "0"; "") & yr; 
  m = Month ( MyDateField ); ms = If( Length(m) = 1; "0"; "") & m; 
  d = Day ( MyDateField ); ds = If( Length(d) = 1; "0"; "") & d
];
  CIA_CODE128(ys & ms & ds)
)

When you use a bar code function, this will reduce the size of date bar codes and also allows you to use bar code types that only allow numeric characters.

UCC/EAN-128 requires dates formatted as above.

Yes/No fields

The standard function If( ) is very useful for printing Yes/No fields as any two values. For example, you can use If( ) to print a field as Y or N instead of Yes and No, using the following expression;

If( MyField=0, "N", "Y" )

When you use a bar code function, this will produce small bar codes of equal length, containing Y or N;

CIA_CODE128 ( If ( MyField = 0, "N", "Y" ) )

Because Code 128 can store 2 digits (0-9) in the same space as one letter (A-Z,a-z) a series of Yes / No fields are best stored as 0's or 1's. For example YNYYNN, printed as 101100 instead, produces a bar code almost as wide.

CIA_CODE128 ( 
  If ( MyField1 = 0, "0", "1" ) &
  If ( MyField2 = 0, "0", "1" ) &
  If ( MyField3 = 0, "0", "1" )
)

If you need other examples, see Technical Support.

 

 


Copyright 2000 CIA (BAR CODES) UK. All rights reserved. Reproduction prohibited.