Appending Extra Options to a List Field in OpenOffice Base

Many forms have at least one drop down field that provides a list of choices, with one option being an “other, please specify” type field. In OpenOffice Base, the source providing the list of options could be another table. In this case, you do not want to add an entry into the source table just to represent other. In such a case, you can use a macro to make the option appear.

To add the other option, the macro, essentially, needs to obtain the field’s controller and then use the controller to append the option. Obtaining the control for the field works like any other field, so I have wrapped this up in a function:


 1 function getControl(form, fieldName as String) as Object
 2     dim model as Object
 3     dim controller as Object
 4
 5     model = form.getByName(fieldName)
 6     controller = ThisComponent.getCurrentController()
 7     getControl = controller.getControl(model)
 8 end function

Next, use the field’s controller to add in the option:

10 sub formInitialisation(event as Object)
11     dim form as Object
12     dim othersModel as Object
13     dim choiceControl as Object
14
15     form = ThisComponent.drawPage.forms(0)
16
17     choiceControl = getControl(form, "universityField")
18     choicesCount = choiceControl.getItemCount()
19     choiceControl.addItem("Other University", choicesCount + 1)
20 end sub

The formInitialisation subroutine has just been set to look for a field that has been named “universityField” (at line 17) and adds the appends the option “Other University” (at line 19) to the list of options. Of course, the macro makes the assumption that a field with the name actually exists on the form and that the field is drop down list field.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: