Faq/Base/134

How can I format a field as uppercase/lowercase?
This is how to make the entry of a field "Name" all uppercase and make only the first letter of the field "Firstname" uppercase.

There are two different solutions: using a masked field or a macro.

Whichever solution is chosen, it is useful to define the relevant fields in the table holding the data with the format "Text [VARCHAR_IGNORECASE]". The searches or selections from queries will be easier because they will be case insensitive.

Using a field mask
In the entry form, choose the "Masked field" control. This control is an entry field, which has two particular properties relevant to this task.

To convert the field "Name" to uppercase automatically use the code "X":
 * All characters are allowed (this is not limited to letters because it is possible to enter hyphens or apostrophes
 * Automatic conversion from lowercase to uppercase


 * The permitted number of characters is indicated by the number of the X characters
 * Field validation: Yes

To capitalise just the first letter of the field "Firstname", use the code "A" followed by "x":
 * The code "A" allows only the capital letters A-Z to be entered (hyphens and apostrophes aren't allowed at the beginning of a name): if a lowercase letter is entered it is automatically converted to uppercase.
 * With "x" all characters are allowed.

Using a macro
It is possible to associate a macro with the event "Before update" of text fields. This event is triggered before the content of the changed control is written to the database.

We can change everything that has been entered with the uppercase/lowercase conversion.

Below is the code for two Python procedures "PysCapitaliseAll" and "PysCapitaliseOne" which are associated with the entry fields "Name" and "Firstname" respectively.

The procedures take as a parameter the contents of the control in question. They change the text contained in the text field.


 * PysCapitaliseAll changes everything to uppercase.
 * PysCapitaliseOne changes only the first character to uppercase.


 * File:FR.FAQ BASE 134 Capitaliser.odb Download an example database

Notes