There’s a question and answer (LibreOffice Base; Tab order from mainform to subform) on SO which almost solve the question 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:
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 instead of the current record.
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 focus on the subform at the current record by pressing Tab
?