| View previous topic :: View next topic |
| Author |
Message |
beginnerAP General User

Joined: 29 Jun 2010 Posts: 29
|
Posted: Thu Jul 29, 2010 2:27 am Post subject: [Solved] Accessing subform values |
|
|
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. 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 |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 2696 Location: Apeldoorn, Netherland
|
Posted: Thu Jul 29, 2010 3:51 am Post subject: |
|
|
Hello
Looks me perfect code for standalone forms but not for embedded forms.
Romke |
|
| Back to top |
|
 |
beginnerAP General User

Joined: 29 Jun 2010 Posts: 29
|
Posted: Thu Jul 29, 2010 4:07 am Post subject: |
|
|
Hi Romke
Not sure what you mean...Surely a sub form is embedded? |
|
| Back to top |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 2696 Location: Apeldoorn, Netherland
|
Posted: Thu Jul 29, 2010 4:57 am Post subject: |
|
|
Hello
I have post here an explanation what maybe can help you.
Romke |
|
| Back to top |
|
 |
beginnerAP General User

Joined: 29 Jun 2010 Posts: 29
|
Posted: Thu Jul 29, 2010 5:18 am Post subject: |
|
|
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 |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 2696 Location: Apeldoorn, Netherland
|
Posted: Thu Jul 29, 2010 5:31 am Post subject: |
|
|
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 |
|
 |
beginnerAP General User

Joined: 29 Jun 2010 Posts: 29
|
Posted: Thu Jul 29, 2010 6:02 am Post subject: |
|
|
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?
Thanks Romke |
|
| Back to top |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 2696 Location: Apeldoorn, Netherland
|
Posted: Thu Jul 29, 2010 6:41 am Post subject: |
|
|
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 |
|
 |
dacm Super User


Joined: 07 Jan 2010 Posts: 734
|
Posted: Thu Jul 29, 2010 6:49 am Post subject: Re: Accessing subform values |
|
|
| 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 + Migrating 'Embedded databases' |
|
| Back to top |
|
 |
beginnerAP General User

Joined: 29 Jun 2010 Posts: 29
|
Posted: Thu Jul 29, 2010 7:14 am Post subject: |
|
|
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
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  |
|
| Back to top |
|
 |
dacm Super User


Joined: 07 Jan 2010 Posts: 734
|
Posted: Thu Jul 29, 2010 7:34 am Post subject: |
|
|
| 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 + Migrating 'Embedded databases' |
|
| Back to top |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 2696 Location: Apeldoorn, Netherland
|
Posted: Thu Jul 29, 2010 7:45 am Post subject: |
|
|
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 |
|
 |
beginnerAP General User

Joined: 29 Jun 2010 Posts: 29
|
Posted: Thu Jul 29, 2010 7:58 am Post subject: |
|
|
Thank you both for your responses - I've found the problem.. yeay!! It would help if I had all the links in the chain!
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 |
|
 |
beginnerAP General User

Joined: 29 Jun 2010 Posts: 29
|
Posted: Thu Jul 29, 2010 10:40 am Post subject: |
|
|
| RPG wrote: | | I think use the Basetools of Benitez. |
Why didn't I download these before.. they're great! Thanks Romke!  |
|
| Back to top |
|
 |
|