AlphaPress Publishing
P.O. Box 5942 Albany, NY 12205
Tel: 518-250-3890


Section Menu 

Are you a University or College bookstore and want to order multiple books?  Email us at or call us at 518-250-3890.  We will be happy to talk to you.  

Are you a professor and you need a sample copy?  We will be happy to send you a pdf or printed copy!  Email us at

Are you outside the United States?  We can ship multiple books worldwide in most countries.




Compare fields using the CBool() function

To contact the author click here

This article is from the book "Access 2007 Pure SQL

To download the sample database click here


The CBool() function

Compare customer first and last name values


The cbool() function will return a true or false value.  To demonstrate its usefulness, let us assume that a coworker comes to our office and says that something is wrong with the mailing labels they are producing.  On certain occasions, the last and first name fields print the same.  Obviously, someone typed in the same value as both first and last name in the database.  We can use the cbool() function to find the records for which this occurs. 


SELECT CustomerID, cbool([lastname]=[firstname]) As TrueFalse

FROM customers



Whenever you see 0 in Access 2007, this means the result is false, or, in other words, the last and first names have different values since you checked for equality.  If you see -1, the result is true, which means that the first and last names have identical values.  As you scroll through the records, you will notice that you get a -1 for customerid = 19 and an error for 106.

This is cause for investigation.  For record 19, last and first names are the same, while for record 106, the first name value is missing!  Consequently, with one function, we found two errors that would mess up our coworker’s job.  Now, we can correct them and send him on his way to produce correct mailing labels.