[SOLVED] Problem with the GetByName function.

Creating and using forms
Post Reply
carltonmatthew
Posts: 2
Joined: Sat Nov 03, 2018 4:56 pm

[SOLVED] Problem with the GetByName function.

Post 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

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
User avatar
Zizi64
Volunteer
Posts: 11358
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Problem with the GetByName function.

Post 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.
Last edited by Zizi64 on Tue Nov 20, 2018 8:42 pm, edited 1 time in total.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
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.
UnklDonald418
Volunteer
Posts: 1546
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Problem with the GetByName function.

Post 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.
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
carltonmatthew
Posts: 2
Joined: Sat Nov 03, 2018 4:56 pm

Re: Problem with the GetByName function.

Post 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.
libreOffice 5.1.6.2 Xubuntu 16.04 64bit
Post Reply