Open a form in Libreoffice/Openoffice Base with a specific filter/query

4.3k Views Asked by At

I am creating a Libreoffice Base with multi forms. Form1 is linked to "Projects" table and each Project has multiple tasks, I can display the tasks as sub form within the same Form1, however, each project has many tasks and each task also has sub tasks so I want to have the tasks be in their own form, lets call it Form2.

I created a push button in Form1 that will open Form2, however, I don't know how to make it open that form and only display the tasks that are related to the project that was being displayed while pressing the push button.

So far here is what I have been able to do:

Reading the projectID which I want to display the tasks for (it is in a textbox called txtProjectID inside Form1):

Doc = StarDesktop.CurrentComponent
Form = Doc.DrawPage.Forms.GetByIndex(0)
ProjID = Form.getByName("txtProjectID").Text

To open the tasks form Form2 i found two ways:

Dim Args(1) As New com.sun.star.beans.PropertyValue
Args(0).Name = "ActiveConnection"
Args(0).Value = Form.ActiveConnection
Args(1).Name = "OpenMode"
Args(1).Value = "open"
oForm = thisComponent.Parent.getFormDocuments
oForm.loadComponentFromURL("Form2","_blank",0, Args())

and

oForm = ThisDatabaseDocument.FormDocuments.getByName("Form2")
oForm.Open

both works to open the tasks form but I couldn't find a way to pass the projectID to only load records related to that project. I couldn't also find a good documentation for the Args().

The question is, how can I open Form2 and display only records related to the projectID from Form1?, also I want to be able to add new records to Form2 under the same projectID (not just a view).


Update

I was able to apply the filter with this code:

odoc2 = thiscomponent
FormModel = odoc2.drawpage.forms.getbyindex(0) 
FormModel.Filter =("Tasks.projectID = " & ProjID)
FormModel.ApplyFilter = True
FormModel.reload()

However, since I am running it from the same Sub that opens Form2 it get applied to Form1 (which called the Sub). How can I get it to work on Form2 instead?

1

There are 1 best solutions below

0
On

Your question provided most of the answer, which only needed some exploring with dbg_methods. The object variable FormModel2 in example below is what you are looking for:

frm_container = ThisDatabaseDocument.FormDocuments.getByName("Form2")
frm_container.open
FormModel2 = frm_container.component.getDrawPage.getforms.getbyindex(0)
FormModel2.Filter [....]

This works when run from "Form1".

Alternatively, you could permanently store the value that is supposed to be the subject of the filter in a separate table/row.