English
Ask Your Question
0

Open form via macro in Libreoffice Base

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 close merge delete

3 answers

Sort by » oldest newest most voted
0

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")
form_container.open
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):

main_form.next
main_form.previous
main_form.absolute(<index>)

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'"
main_frm.ApplyFilter
main_frm.reload()

Old question, but popular, hope this helps.

edit flag offensive delete link more
0

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
0

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
Login/Signup to Answer

Stats

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

Seen: 1,708 times

Last updated: Feb 01