We will be migrating from Ask to Discourse on the first week of August, read the details here

Ask Your Question

Open form via macro in Libreoffice Base [closed]

asked 2012-11-06 22:17:58 +0200

sdy7 gravatar image

Hi I'm trying to make my database user friendly and I have a question:

From one form, A, I'm launching another form, B, using a button with this macro attached:

Sub openFormByTag(oEv)
    cWhat = com.sun.star.sdb.application.DatabaseObject.FORM
    oModel = oEv.Source.getModel()
    sName = oModel.Tag
    oView = oModel.Parent.Parent.Parent.Parent.getCurrentController()
    oView.loadComponent(cWhat, sName, FALSE)
End Sub

Works fine, but: I would like to specify a row id or something in form A so that form B scrolls automatically to the the particular row I want to view or edit.

Doe anyone have an idea about how this can be done?

Or maybe where there are some comprehensible documentation for this kind of issue perhaps?

Thanks in advance. Soren

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2020-10-02 11:49:10.948399

4 Answers

Sort by » oldest newest most voted

answered 2015-02-01 06:24:20 +0200

doug gravatar image

The cleanest way to explore functions and methods in LO Basic is to identify the object in question and then execute:

MsgBox target_object.dbg_properties
MsgBox target_object.dbg_methods

The best API reference is here but it is not so user-friendly.

For the functional question, I have found most useful an alternative syntax, which refers to the form root and controller::

root_doc = ThisComponent
form_container = root_doc.Drawpage.Forms
form_ctrlr = root_doc.getCurrentController()
main_form = form_container.getByName("MainForm")

For opening a form, I have seen this, which appears to get to the same place:

form_container = ThisDatabaseDocument.FormDocuments.getByName("Form1")
main_form = frm_container.component.getDrawPage.getforms.getbyindex(0)

Functions for moving to different rows in the record source are, among others (look at .dbg_methods):


You could use those commands and test the values of controls on your form as you go.

A better way would to filter the contents of the form. Of course, there would be a limited recordset visible, but it would be fast and clean:

main_frm.Filter = " ""frmB_col"" = 'frmA_data'"

Old question, but popular, hope this helps.

edit flag offensive delete link more

answered 2012-11-25 06:22:31 +0200

Q gravatar image

Can you explain line by line what is going on?

edit flag offensive delete link more

answered 2012-11-26 09:00:13 +0200

sdy7 gravatar image

Well, partly. I am a progammer, but have no experience in Basic and the libre/openoffice API frameworks. I got the code from another post somewhere. The name of the form to open is stored in the tag member of the calling button. That way I can reuse the routine to launch other forms. Why do you ask? Do you know about a solution?

edit flag offensive delete link more

answered 2017-04-29 00:33:42 +0200

EasyTrieve gravatar image

UPDATE, while @doug's answer is valid, I think the MRI introspection tool provides a much better, quicker and more interactive way to see what's going on.

edit flag offensive delete link more

Question Tools


Asked: 2012-11-06 22:17:58 +0200

Seen: 9,556 times

Last updated: Apr 29 '17