OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

[Solved] Accessing subform values

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Base
View previous topic :: View next topic  
Author Message
beginnerAP
General User
General User


Joined: 29 Jun 2010
Posts: 29

PostPosted: Thu Jul 29, 2010 2:27 am    Post subject: [Solved] Accessing subform values Reply with quote

Hi again

I'm having a spot of trouble accessing controls in subforms. I've searched the forum and used the methods described but getting the NoSuchElementException error, which I know means it doesn't recognise the control name I'm looking for. Confused Can someone tell me where i'm going wrong please. I've tried these two pieces of code:
Code:
Dim mainForm as Object
mainForm = ThisComponent.DrawPage.Forms.GetByIndex(0)
Dim subForm as Object
subForm = mainForm.GetByName("SubForm")
Dim textbox as Object
textbox = subForm.GetByName("TB1")

Code:
dim textbox as object
textbox = ThisComponent.drawpage.forms(0).getByName("SubForm").getbyname("TB1")


Many thanks


Last edited by beginnerAP on Thu Jul 29, 2010 8:14 am; edited 1 time in total
Back to top
View user's profile Send private message
RPG
Super User
Super User


Joined: 24 Apr 2008
Posts: 2697
Location: Apeldoorn, Netherland

PostPosted: Thu Jul 29, 2010 3:51 am    Post subject: Reply with quote

Hello

Looks me perfect code for standalone forms but not for embedded forms.

Romke
Back to top
View user's profile Send private message
beginnerAP
General User
General User


Joined: 29 Jun 2010
Posts: 29

PostPosted: Thu Jul 29, 2010 4:07 am    Post subject: Reply with quote

Hi Romke

Not sure what you mean...Surely a sub form is embedded?
Back to top
View user's profile Send private message
RPG
Super User
Super User


Joined: 24 Apr 2008
Posts: 2697
Location: Apeldoorn, Netherland

PostPosted: Thu Jul 29, 2010 4:57 am    Post subject: Reply with quote

Hello

I have post here an explanation what maybe can help you.

Romke
Back to top
View user's profile Send private message
beginnerAP
General User
General User


Joined: 29 Jun 2010
Posts: 29

PostPosted: Thu Jul 29, 2010 5:18 am    Post subject: Reply with quote

Thanks for that - they are embedded forms as these forms don't exist outside the database.

Does that impact the way I wrote the code above?[/quote]
Back to top
View user's profile Send private message
RPG
Super User
Super User


Joined: 24 Apr 2008
Posts: 2697
Location: Apeldoorn, Netherland

PostPosted: Thu Jul 29, 2010 5:31 am    Post subject: Reply with quote

Hello

The answer can not be clear. It depends of the method how you run the code. In your case activate the code with a button. Follow first the example what I give.

Also I think start study a tutorial about basic. You have to learn how that works. You give me not any information. Not even where you get an error.

Romke
Back to top
View user's profile Send private message
beginnerAP
General User
General User


Joined: 29 Jun 2010
Posts: 29

PostPosted: Thu Jul 29, 2010 6:02 am    Post subject: Reply with quote

ah - so does a macro like this need to run on a sub form from a button?
RPG wrote:

It depends of the method how you run the code. In your case activate the code with a button.

I have a form and, obviously, a subform in that. There is a combobox in the sub form and I wanted to get the value from the combobox on the event "text modified". I'm trying to use this code to get that text
Code:
textbox = ThisComponent.drawpage.forms(0).getByName("SubForm").getbyname("TB1")


RPG wrote:

You give me not any information. Not even where you get an error.

The error is on the code line above and says NoSuchElementException error which makes me think it cannot find "TB1" on the "SubForm". I don't get any errors for
Code:
ThisComponent.drawpage.forms(0).getByName("SubForm")
so makes me think it is at least finding the "SubForm"


Does this help with understanding what I am doing? Confused

Thanks Romke
Back to top
View user's profile Send private message
RPG
Super User
Super User


Joined: 24 Apr 2008
Posts: 2697
Location: Apeldoorn, Netherland

PostPosted: Thu Jul 29, 2010 6:41 am    Post subject: Reply with quote

Hello

You conclusion is perfect.

You must forst start with the mainform in which the subform is. You must follow the same way as you see in the form navigator.
Code:
dim oDoc,oDrawpage,oForms,oMainForm,oSubForm,oTextbox
oDoc=ThisComponent
oDrawpage=oDoc.drawpage
oForms=oDrawpage.forms
oMainForm=oForms.getbyname"(MainForm")
oSubForm=oMainForm.getByName("SubForm")
oTextbox=oSubForm.getByName("TB1")
I knew this is much more text but it helps you to find the error. Your problem is have have not learned how the forms are working. I think use the Basetools of Benitez. That are good tools and you can also learn how to code. Good coding is difficult also for me. When you work with basic and the API then it is important to understand the services and interfaces.
But I believe it is more important to understand the working of the forms and SQL. Also important is understand of OOo self. Real often you can see that somebody is programming a part what can be easy done with a standard code.

Romke

Romke
Back to top
View user's profile Send private message
dacm
Super User
Super User


Joined: 07 Jan 2010
Posts: 769

PostPosted: Thu Jul 29, 2010 6:49 am    Post subject: Re: Accessing subform values Reply with quote

beginnerAP wrote:
Code:
Dim mainForm as Object
mainForm = ThisComponent.DrawPage.Forms.GetByIndex(0)
Dim subForm as Object
subForm = mainForm.GetByName("SubForm")
Dim textbox as Object
textbox = subForm.GetByName("TB1")

Code:
dim textbox as object
textbox = ThisComponent.drawpage.forms(0).getByName("SubForm").getbyname("TB1")

Let's see. All this code looks perfect. I use this same syntax and variations commonly in .odb-embedded forms triggered by various events including button controls. Make sure the subform and control names are exact including capitalization. And finally, make sure the macro is located in the applicable .odb as opposed to My Macros. Also, bring up the Form Navigator and make sure the textbox (TB1) is actually located on the subform.
_________________
Soli Deo gloria
Tutorial: avoiding data loss with Base + Splitting 'Embedded databases'
Back to top
View user's profile Send private message
beginnerAP
General User
General User


Joined: 29 Jun 2010
Posts: 29

PostPosted: Thu Jul 29, 2010 7:14 am    Post subject: Reply with quote

Romke - I'be used your code and it's definitely the "TB1" field i'm having problems with.. it is where the exception is coming up again. I'm downloading the Basetool from Benitez and I'll see how I get on... I thought I understood forms enough to be able to retrieve data from controls on them but the sub forms has stumped me! Thanks Smile

Dacm - I've checked and re-checked the wording to be sure I didn't miss anythign but no joy there. The macro is also in my .odb (along with all my others) not the "My Macros" one.. I've even gone to the extent or re-doing the form but still no joy! I'll try it all again.. maybe I'm missing something! Thanks too Very Happy
Back to top
View user's profile Send private message
dacm
Super User
Super User


Joined: 07 Jan 2010
Posts: 769

PostPosted: Thu Jul 29, 2010 7:34 am    Post subject: Reply with quote

beginnerAP wrote:
... I thought I understood forms enough to be able to retrieve data from controls on them but the sub forms has stumped me!

I think you do understand well enough because there's nothing wrong with your code from a syntax standpoint. Did you check the location of the textbox using the Form Navigator?
_________________
Soli Deo gloria
Tutorial: avoiding data loss with Base + Splitting 'Embedded databases'
Back to top
View user's profile Send private message
RPG
Super User
Super User


Joined: 24 Apr 2008
Posts: 2697
Location: Apeldoorn, Netherland

PostPosted: Thu Jul 29, 2010 7:45 am    Post subject: Reply with quote

Hello

Maybe for your information there is a different between my code and the original code I will show it.

Code:
dim textbox as object
textbox = ThisComponent.drawpage.forms(0).getByName("SubForm").getbyname("TB1")

dim textbox as object
textbox = ThisComponent.drawpage.forms.getbyname("mainForm").getByName("SubForm").getbyname("TB1")


There are two reason for study the tutorials
a) You learn the language.
b) The language give you also tools for testing the code. One of the possibillities is:Hasbyname and getbyindex.
I will show you what it is doing.

Code:
sub rty
dim oDoc,oDrawpage,oForms,oMainForm,oSubForm,oTextbox
oDoc=ThisComponent
oDrawpage=oDoc.drawpage

oForms=oDrawpage.forms
print oForms.hasbyname("MainForm")
print oForms.getbyindex(0).name

oMainForm=oForms.getbyname("MainForm")
print oMainForm.hasbyname("SubForm")
print oMainForm.getbyindex(0).name

oSubForm=oMainForm.getByName("SubForm")
print oSubForm.hasbyname("TB1")
print oSubForm.getbyindex(0).name

oTextbox=oSubForm.getByName("TB1")

end sub
Back to top
View user's profile Send private message
beginnerAP
General User
General User


Joined: 29 Jun 2010
Posts: 29

PostPosted: Thu Jul 29, 2010 7:58 am    Post subject: Reply with quote

Thank you both for your responses - I've found the problem.. yeay!! It would help if I had all the links in the chain! Embarassed

And for those that might be experiencing the same problem.. make sure you count in the grid if you are using a table control!
Code:
dim oDoc,oDrawpage,oForms,oMainForm,oSubForm,oTextbox, otblctrl
oDoc=ThisComponent
oDrawpage=oDoc.drawpage
oForms=oDrawpage.forms
oMainForm=oForms.getbyname("MainForm")
oSubForm=oMainForm.getByName("SubForm")
otblctrl=oSubForm.getByName("SubForm_Grid") '***this bit!
oTextbox=otblctrl.getByName("TB1")


Thanks again everyone.. off to check out this new extension now!
Back to top
View user's profile Send private message
beginnerAP
General User
General User


Joined: 29 Jun 2010
Posts: 29

PostPosted: Thu Jul 29, 2010 10:40 am    Post subject: Reply with quote

RPG wrote:
I think use the Basetools of Benitez.


Why didn't I download these before.. they're great! Thanks Romke! Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Base All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group