Ask Your Question

Multiple Tags autocompletion field in Base [closed]

asked 2015-07-10 10:31:10 +0100

mokas01 gravatar image

updated 2020-08-18 22:12:28 +0100

Alex Kemp gravatar image


I would like to create a tag field in Base. I used a combo box. I have something nice and working (with autocompletion) but, I don't know how to enter multiple tags for one object. If I do so, and whatever the separator I used, its always handled as one new tag : "tag1; tag2" has become a third one, although I don't want to. Have you got an idea on how I could do this ?


Component : Base LibreOffice for OSX

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by Alex Kemp
close date 2020-07-19 19:41:09.385950

2 Answers

Sort by » oldest newest most voted

answered 2015-07-11 00:39:14 +0100

frofa gravatar image

updated 2015-07-12 08:33:43 +0100

One way of doing this is to add another 2 tables - TAGS and TAGS_CHOSEN - to your design. The first of these contains one row per tag (and will be used to populate your 'choose a tag' listbox as below) - you might already have this table in your design to populate your 'choose a tag' combo box. Rows in the second TAGS_CHOSEN table are in a 1:n relationship to your primary table records (i.e. one primary record is linked to multiple rows in the TAGS_CHOSEN table via the primary record ID). Your FORM would have a tag list (using a data-grid control) in a subform which gets filtered according to the selected primary record, and each new tag may be added via a drop-down listbox (field-type in the data-grid column) with its tag-list sourced from the TAGS table. You could even have an extra column in your TAGS_CHOSEN table to store a batch number so you could recall previous search-tag/keyword combinations - see HERE.

edit flag offensive delete link more


the subform/child-table approach is the way. There is a multiselection property for the List box, but it is broken on at least some platforms. The only additional alternative is to use a macro-heavy approach consisting of direct-SQL writes to the table and reloads of a child form, which probably is more trouble than it is worth.

doug gravatar imagedoug ( 2015-07-11 04:26:37 +0100 )edit

answered 2015-07-11 17:32:36 +0100

pierre-yves samyn gravatar image


LibreOffice's database is relational. With such databases, multi-valued fields are indeed managed by related tables. This is why listboxes only allow multi-select if the control is not bound to a database field.

With listbox not bound to a database field, a macro can collect selected items, and assign them to a field. In the following MultiSelect.odb the macro is associated to the click of the button.


Here is the code:

Sub MultiSelect(oEvt)

const sep = "|"

dim oForm as object, oListCtrl as object, oCtrl as object
Dim i as integer

oForm = oEvt.source.model.parent
oListCtrl = oForm.getByName("ListBox1")
oCtrl = oForm.getByName("Fruit")

with oListCtrl
    select case ubound(.SelectedValues())
        case -1
            msgbox "no selection", 64, "Multiselect"        
        case 0
            oCtrl.text = .SelectedValues(0)
        case > 0    
            oCtrl.text = ""
            for i = 0 to  ubound(.SelectedValues()) - 1
                oCtrl.text = oCtrl.text & .SelectedValues(i) & sep
            next i  
            oCtrl.text = oCtrl.text & .SelectedValues(i)
        case else   
            msgbox "This should not occur...", 64, "Multiselect"        
    end select
end with

end sub

As you can see, the separator | is given at the beginning of the macro. You can replace by what you want...

Finally, as the listbox is not associated with a field, it is not cleared on record changing. The following macro allows for example to reset the list. It is associated with the form event "After changing".

sub ChangeRecord(oEvt)

dim oForm as object, oListCtrl as object

oForm = oEvt.source
oListCtrl = oForm.getByName("ListBox1")
oListCtrl.SelectedValues() = array()

end sub

If this answers the question, thank you to click on the ✔ to mark it ANSWERED.


edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-07-10 10:31:10 +0100

Seen: 1,469 times

Last updated: Jul 12 '15