Search code examples
libreofficelibreoffice-base

How to get focus on a subform in LibreOffice Base using tab


The question and answer LibreOffice Base; Tab order from mainform to subform almost solve the issue I have, but not completely.

I have a table mytable (id, name, textfield). I'm displaying id and name in a form with a table layout (table control). I've added the column textfield from the same table as a subform with a text box control (the reason is that I want to enter text with newlines, while being able to navigate the records quickly in the main table). Here's what it looks like in design view:

Form and subform from one table

I've added this Basic macro, based on the two answers linked above:

Sub Main

Dim root_doc As Object
Dim form_container, form_ctrlr As Object
Dim main_frm, sub_frm, tab_target As Object
root_doc = ThisComponent
form_container = root_doc.Drawpage.Forms
form_ctrlr = root_doc.getCurrentController()
main_frm = form_container.getByName("MainForm")
sub_frm = main_frm.getByName("SubForm")
tab_target = sub_frm.getByName("TextField")
form_ctrlr.getControl(tab_target).setFocus()

End Sub

Now, if I add the macro on the event When losing focus of the name column, I do get focus on the textbox when pressing Tab, but on the next row.

If I add the macro to the event On key press of the name column, I get what I want when pressing e.g. Space, but Tab or Enter only take me to the next row in the main form.

Is there a way to get this to work with Tab?


Solution

  • Options to solve this, from the answers over at ask.libreoffice.org:

    1. Just use the standard Ctrl + Tab to switch focus.

    2. Assign a macro to a custom key combination and use that. Not all combinations work, I settled on Shft + Enter.

    And the macro (provided by user Ratslinger):

    Sub Main
        Dim oForm, oCtrlr, oField As Object
        oForm = ThisComponent.Drawpage.Forms.getByName("MainForm")
        oCtrlr = ThisComponent.getCurrentController()
        oField = main_frm.getByName("TextField")
        oCtrlr.getControl(oField).setFocus()
    End Sub