Creating bar codes using a FoxPro Query

Creating bar codes in a query is a very powerful method. Queries can be used as the source of data;

Design your Query - without bar codes

Create a new query, or open an existing query to modify it.

Before adding bar codes, run your query and check that your query is producing the correct data (the data you want to print as a bar code).

Note: The query must include the field(s) you want to print as bar codes.

Note: If the bar code will contain more than one field, or parts of one or more fields, then you must use regular FoxPro expressions to calculate the data.

For example, if the bar code must contain two fields, you must add the two fields using an expression / calculation to produce a single field.

Before you add bar codes to your Query

Question 1: Is your query producing the correct data?

Question 2: In the query results, can you see a single field that contains the correct data (that data you want to print as bar codes)?

If both answers are Yes, then you make your query calculate bar codes.

If either answer is No, then modify your query - until you can see the correct data in the query results (the data you want to print as bar codes).

Using the SET LIBRARY command

To give your application access to functions in a library, use the SET LIBRARY command, which will open the external Application Program Interface (API) library.

See: Using the SET LIBRARY command

Calculating Code 128 bar code example

Bar codes are calculated using bar code functions. See Bar code functions for a complete list or all bar code functions, that you can use to create all types of bar codes. For example, use function CIA_ITF_A() to create Interleaved 2-of-5 (ITF) bar codes, use function CIA_CODE128() to create Code 128 bar codes, etc.

Note: Before you run your Query, you must use the SET LIBRARY command to give your application access to functions in a library. See: Using the SET LIBRARY command

Example: If you want to print a field called StockNumber as a Code 128 bar code, then use this expression in your Query.

CIA_CODE128( StockNumber )

Because character fields contain trailing spaces, you must remove them when you use a bar code function.

RTRIM ( StockNumber)

So the complete calculation becomes;

CIA_CODE128( RTRIM ( StockNumber) )

If your calculated bar codes are different lengths, then you must pad the bar code result with spaces.

PADR( CIA_CODE128 ( RTRIM ( StockNumber ) ), 254, " ")

Interleaved 2-of-5 (ITF) bar code example

Example: If you want to print a field called StockNumber as an Interleaved 2-of-5 (ITF) bar code, then use this expression in your Query.

To create Interleaved 2-of-5 (ITF) bar codes of StockNumber field;

PADR( CIA_ITF_A ( RTRIM ( StockNumber ) ), 254, " ")

To create the human readable number below the Interleaved 2-of-5 (ITF) bar code;

PADR( CIA_ITF_A_H ( RTRIM ( StockNumber ) ), 254, " ")

Printing bar codes

To print bar codes you must print the bar code field using a bar code font. See Bar code font name and font size to use for more details. For example, to print Code 128 bar codes use font name CIA Code 128 Medium and font size 14. To print Interleaved 2-of-5 bar codes use font name CIA ITF Medium and font size 14, etc.

Note: Usually you would use the Query in a Report and print the field in the Report. In the Report you would select the bar code font. See: Printing bar codes in FoxPro

Printing human-readable text below the bar code

There are also functions to calculate the Human Readable text - to print below the bar code.

These functions are only necessary for some type of bar code - bar codes that have a check digit (or check character).

 

See: Printing bar codes in a FoxPro Report

 


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