Ask Your Question
1

how to access to the controls of a base form with basic ?

asked 2016-01-19 15:52:31 +0200

Jérôme gravatar image

I created a form into a LO Base with the WYSIWYG form editor. Next I would like to access to the controls which are inside this form. However the 2nd line of the below code raises the exception "Property or method not found : getByName" (translation of french terms "Propriété ou méthode non trouvée : getByName").

form = ThisDatabaseDocument.FormDocuments.getByName("myForm") textArea = form.getByName("Console")

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2016-01-19 23:38:30 +0200

peterwt gravatar image

updated 2016-01-29 17:33:21 +0200

If you add the MsgBox line as shown below:-


form = ThisDatabaseDocument.FormDocuments.getByName("myForm")
MsgBox form.dbg_properties
textArea = form.getByName("Console")

you will see that the MsgBox shows
Properties of object
"com.sun.star.comp.dba.ODocumentDefinition":
so the form object created is not the form but the Form Document Definition.
Change the code to


form = ThisComponent.Drawpage.Forms.getByName("myForm")
MsgBox form.dbg_properties
textArea = form.getByName("Console")

and the MsgBox will show
Properties of object
"com.sun.star.comp.forms.ODatabaseForm":
so the form object is now your Form.
You get the error on your second line as there is no getByName() method for the DocumentDefinition object.

EDITED 29/01/2015

How are you running the Macro? If you run it from a form event such as a button click or from the Toolbar on the Form Tools>Macros>Run Macro it will work. If you run it from the toolbar on the main LO window or from the Macros Window it will fail. ThisComponent or ThisDatabaseDocument points to the Document that has the focus so the Form must have the focus.

There is a quick way of getting the Form Object using the Macro below.


Sub Button(e)
oForm = e.Source.Model.Parent
End Sub

The Macro is run from a Button Click event on a Button on the Form. The Argument (e) is required in the Macro. When run the Argument e is passed to the Macro. The Source of the event e is the Button Object and the Parent of the Button is the Form Object.

edit flag offensive delete link more

Comments

The code you suggested fails on the first line with the below error : "Property or method not found : Drawpage" (translation of french terms "Propriété ou méthode non trouvée : Drawpage").

Jérôme gravatar imageJérôme ( 2016-01-20 16:44:59 +0200 )edit

@Jérôme I have edited my original reply as it is too long to fit in a comment.

peterwt gravatar imagepeterwt ( 2016-01-29 17:34:07 +0200 )edit

You might find this useful:- https://wiki.openoffice.org/wiki/Docu...

peterwt gravatar imagepeterwt ( 2016-01-30 17:20:30 +0200 )edit
0

answered 2018-06-11 23:10:36 +0200

Jim K gravatar image

The following code works when run from the main Base window. The code is partly from https://ask.libreoffice.org/en/questi....

    form_container = ThisDatabaseDocument.FormDocuments.getByName("Form1")
    form_container.open
    Wait 500
    main_form = form_container.Component.getDrawPage().getForms().getByIndex(0)
    control = main_form.getByName("txtName")
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

2 followers

Stats

Asked: 2016-01-19 15:52:31 +0200

Seen: 4,450 times

Last updated: Jun 11 '18