Frequently asked questions - Base

From The Document Foundation Wiki
< Faq‎ | Base
Jump to: navigation, search

How can I format a field as uppercase/lowercase?

Thia is how to make, for example, the entry of a field "Name" to be all uppercase and for the field "Firstname" with only the first letter in 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, just as a text field is, which has, amongst others, two particular properties.

Entry mask Put the character codes, not the data to be entered: one code = one character[1]

The codes determine what the field will accept at that position.

Field validation Yes : Only the characters specified as valid will be accepted

Non : Invalid characters will be removed on leaving the field

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 X's
  • 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 contents 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 table the contents of the control concerned as a parameter. They change the text contained in the text field.

  • PysCapitaliseAll changes everything to uppercase.
  • PysCapitaliseOne changes only the first character to uppercase.
option explicit

sub PysCapitaliseOne(PysEvent)
PysEvent.Source.text = Ucase(left(PysEvent.Source.text, 1)) & Lcase(mid(PysEvent.Source.text, 2))
end sub

sub PysCapitaliseAll(PysEvent)
PysEvent.Source.text = Ucase(PysEvent.Source.text)
end sub