Pluralize Text Based on the Number of Database Records Returned

HotDocs Version:HD6, HD2005, HD2006, HD2007, HD2008, HD2009
Word Processor:Microsoft Word, WordPerfect
Added to Knowledge Base:February 2005

Sometimes you may want to pluralize text in the document based on whether two or more records are retrieved from a database table. For example, perhaps you are creating a list of customers. If there is only one customer in the list, you want the introductory text, Customer, to be singular. However, if there are two or more customers, you want this text to be plural—Customers

Following are two examples of how you can accomplish this using either an expression or a Computation variable.

In the first example, HotDocs checks to see if the second iteration of the key variable that is linked to the database component is answered. (This means you must know that some particular database field will always be answered for any customer in the database.) The computation returns false if 0 or 1 customers are listed, or it returns true if there are 2 or more. 

In the second example, the database component, Customers DB, is repeated. Each time a new record is selected, the counter is incremented. You can then use the result of Customer Count in the expression that merges (or doesn't merge) the plural -s.

Example:

Example 1

ANSWERED (Customer Name[2])

Example 2

SET Customer Count TO 0
REPEAT Customers DB
   INCREMENT Customer Count
END REPEAT

 Customer Name

A Text variable that is linked to corresponding field in a database table

Customer Count

A temporary Number variable used as a counter in the computation. (See Create a Temporary Variable.)

 Customers DB

A repeating database component