[SOLVED] Problem with the GetByName function.

Creating and using forms

[SOLVED] Problem with the GetByName function.

Postby carltonmatthew » Tue Nov 20, 2018 12:58 am

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
Last edited by robleyd on Sat Nov 24, 2018 12:52 pm, edited 2 times in total.
Reason: Add green tick [robleyd, Moderator]
libreOffice 5.1.6.2 Xubuntu 16.04 64bit
carltonmatthew
 
Posts: 2
Joined: Sat Nov 03, 2018 4:56 pm

Re: Problem with the GetByName function.

Postby Zizi64 » Tue Nov 20, 2018 8:28 am

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.
Last edited by Zizi64 on Tue Nov 20, 2018 8:42 pm, edited 1 time in total.
Tibor Kovacs, Hungary; LO4.4.7, LO6.1.5 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.2; AOO4.1.5
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 7814
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Problem with the GetByName function.

Postby UnklDonald418 » Tue Nov 20, 2018 6:49 pm

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.
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.6 & LibreOffice 6.1.5.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1083
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Problem with the GetByName function.

Postby carltonmatthew » Sat Nov 24, 2018 12:20 pm

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.
libreOffice 5.1.6.2 Xubuntu 16.04 64bit
carltonmatthew
 
Posts: 2
Joined: Sat Nov 03, 2018 4:56 pm


Return to Forms

Who is online

Users browsing this forum: No registered users and 2 guests