How to open form with selected record from a table-form

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
strike_lf
Posts: 5
Joined: Sat Feb 04, 2017 3:44 pm

How to open form with selected record from a table-form

Post by strike_lf »

Hi!

I found this macro below online, its function is to open an OpenOffice Base form from another one which contains a table/grid with all records

To be clear: imagine you have a table/grid form with you records and you want to open one particular record from this table. You just want to click on its row to select it and then this macro will open it in a different form with all its details. See picture, please.

But two messages show:
1) "Runtime Error BASIC Variable not defined." and stops on line "forms ThisComponent.Parent.getFormDocuments = ()" in my main project
2) or "runtime error BASIC Property or method not found :. ID." and stops on line "i = oStartForm.columns.ID.getInt" in my attached sample.
:crazy:

I attach also a db sample to understand macro mechanics; my true project is already filled with many personal data and it is more complex.
So I prefer the K.I.S.S. rule...

Code: Select all

Sub ApriFormCompilazioneDaTabella ()
Dim prop(1) as New com.sun.star.beans.PropertyValue
forms=ThisComponent.Parent.getFormDocuments()
conn=ThisComponent.Parent.DataSource.getConnection("","")
prop(0).Name="ActiveConnection"
prop(0).Value=conn
prop(1).Name="OpenMode"
prop(1).Value="open"

oStartDoc = ThisComponent
oStartForm = oStartDoc.drawpage.forms.MainForm
i = oStartForm.columns.ID.getInt

oNewDoc = forms.loadComponentFromURL("Compilazione_by_strike_lf","_blank",0,prop())
oNewDocForm = oNewDoc.drawpage.forms.MainForm
wait 100
oNewDocForm.Filter = "ID ='" & i & "'"
oNewDocForm.ApplyFilter = True
oNewDocForm.Reload
End Sub
Unfortunately I am a rookie when it comes to programming with Basic so I'd like to ask your help. Thank you! :super:
Attachments
explanation.jpg
prova_interrogazioni_2.odb
(24.67 KiB) Downloaded 265 times
OpenOffice 3.1 on Windows Vista
UnklDonald418
Volunteer
Posts: 1549
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: How to open form with selected record from a table-form

Post by UnklDonald418 »

You don't need a macro to do what you are asking.
Place the Detail on a SubForm with your Filter/Research Form as the MainForm and link the two via the ID fields.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
strike_lf
Posts: 5
Joined: Sat Feb 04, 2017 3:44 pm

Re: How to open form with selected record from a table-form

Post by strike_lf »

Yes, you are right. In many cases as in the db sample attached, it's the simplest way to match and combine research and results.
My first research form worked exactly as you described.

Unfortunately I need a macro because my new project is bigger and more complex.
So "Research Form" and "Detail Form" are very different forms, printable as A4 pdf sheets.
There is no space for many boxes and grid, so it is more useful and readable separate them in two distinct forms: one for filter, one for details.

Thanks a lot if someone can help me to correct this macro (possibly by working with attached DB).
OpenOffice 3.1 on Windows Vista
F3K Total
Volunteer
Posts: 1038
Joined: Fri Dec 16, 2011 8:20 pm

Re: How to open form with selected record from a table-form

Post by F3K Total »

Hello,
modify this code line

Code: Select all

oStartForm = oStartDoc.drawpage.forms.MainForm
append

Code: Select all

.SubForm
that it will be

Code: Select all

oStartForm = oStartDoc.drawpage.forms.MainForm.SubForm
and it works.
R
  • MMove 1.0.6
  • Extension for easy, exact positioning of shapes, pictures, controls, frames ...
  • my current system
  • Windows 10 AOO, LOLinux Mint AOO, LO
strike_lf
Posts: 5
Joined: Sat Feb 04, 2017 3:44 pm

Re: How to open form with selected record from a table-form

Post by strike_lf »

Yes, I confirm, it works with attached db sample. Thank you! :bravo:

But in my main project, where grid/table is mainform and filter parameters as subform,
it continues to stop now at line

Code: Select all

conn=ThisComponent.Parent.DataSource.getConnection("","")
I do not understand... :ucrazy:

I follow suggestions from this link:
http://ooo-forums.apache.org/en/forum/v ... 5&p=337281

Maybe someone can help me to understand my mistakes!
OpenOffice 3.1 on Windows Vista
UnklDonald418
Volunteer
Posts: 1549
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: How to open form with selected record from a table-form

Post by UnklDonald418 »

Use the MRI tool or the Xray tool to inspect ThisComponent. For that line of code to fail indicates that ThisComponent probably doesn't return what you are expecting.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
UnklDonald418
Volunteer
Posts: 1549
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: How to open form with selected record from a table-form

Post by UnklDonald418 »

On the sample database you uploaded, the macro is triggered by a “Mouse Button released” event on the subform grid, and the macro code is dependent upon the structure of the calling form.
When you say
But in my main project, where grid/table is mainform and filter parameters as subform
it indicates that the sample database you uploaded is structured differently from your main project. Which means the macro code cannot work with both forms.
What triggers the macro on your "main project"?
When you use MRI to inspect ThisComponent, the Title property should show the name of the database file followed by the name of the current form. Try it in your sample database. The Title should show “prova_interrogazioni_2.odb : Filtro2_by_Charlie”. Then in the MRI window double click the Parent property and now the Title property should show just the database name “prova_interrogazioni_2.odb”. In addition the MRI window should also show Datasource in it's list of properties.
Now look at the MRI results when you trigger the macro from your “main project”. What is the Title? When you double click the Parent property what is the Title now? Does it have a Datasource property?
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Post Reply