Page 1 of 1

[SOLVED] Problem with the GetByName function.

PostPosted: Tue Nov 20, 2018 12:58 am
by carltonmatthew
I've started a new split database using "Split_HSQLDB_Wizard_v3c.odb"
I'm not able to get the GetByName function to work. Its' not able to retrieve either the form name, or control names.
I've transplated existing working code from another database and scoured the forums for examles, all which appear to indicate the coding is correct.
This problem has been holding me up for several weeks now, with no sign of a way forward. :crazy:
Have I just made a simple stupid mistake?
I'm operating LibreOffice 5.1.6.2 on Ubuntu 16.04, and Windows 7

In the example below, I setup a new database with a single form called "MyTestForm" containing a single text box "TextBox1"
The following code is triggered on the TextModified event. (Text Changed ...Standard.FormModule.AfterTextBoxUpdate (document, Basic)"
Code: Select all   Expand viewCollapse view
option explicit
sub AfterTextBoxUpdate(ctrl as control)
'
' After updating the textbox, display contents in a MsgBox
' then change it.
'
   ' add the usual form variable set.
   Dim oDoc As Object
   Dim oDocCtrl As Object
   dim oDrawpage as object
   Dim oForm As Object
   Dim otxtBox as object   'Committee drop down box


   oForm=ctrl.source.Model.Parent
   msgbox oForm.name 'WORKS - displays the form name "MyTestForm"


   oDoc = ThisComponent
   oDrawpage = oDoc.Drawpage
   oForm = oDrawpage.Forms.getbyName("MyTestForm") ' FAILS
   'Error Message : Type: com.sun.star.container.NoSuchElementException Message: .
'
'

end sub

Re: Problem with the GetByName function.

PostPosted: Tue Nov 20, 2018 8:28 am
by Zizi64
Please doynload, install, and use an object inspection tool like the XrayTool or the MRI. Then you will able to display the existing properties, methods and interfaces of the objects by your macro code in a document.

Re: Problem with the GetByName function.

PostPosted: Tue Nov 20, 2018 6:49 pm
by UnklDonald418
I tried your code and it works perfectly for me.
But when I append a space either after or in front of MyTestForm, then I see the NoSuchElementException.

Re: Problem with the GetByName function.

PostPosted: Sat Nov 24, 2018 12:20 pm
by carltonmatthew
Thanks for the pointer to MRI - an essential tool. I eventually found my form "FTscore" contained another "FTscore" sub form within it :knock: which contained only a a few controls. Moving all the controls to the top level (correct location) solved the problem of selecting the incorrect FTscore object. I can now look forward to completing my project.