| View previous topic :: View next topic |
| Author |
Message |
etho201 Newbie

Joined: 29 Apr 2008 Posts: 2
|
Posted: Tue Apr 29, 2008 7:25 pm Post subject: How do I autofill certain fields. |
|
|
I created a table and a form in OpenOffice.org Base... and while using the form.. I want certain fields to equal the same as another field. So that I don't have to manually enter them twice... With spreadsheets this is easy... All I have to do is go to the formula and type something like: =E3 and I'm done. How do I do something like this with Base?
For example... using the forms... Say I have 3 fields..
1. First Name
2. Last Name
3. Full Name
so....
First Name=Bart
Last Name=Simpson
Full Name=Bart Simpson (Make this one autofill from the first 2 fields)
But I don't want to do it in a report... I want it to be reflected in my form/table data.
Thanks! |
|
| Back to top |
|
 |
Voobase OOo Advocate


Joined: 21 Nov 2007 Posts: 400 Location: Australia
|
Posted: Wed Apr 30, 2008 1:11 am Post subject: |
|
|
Hi there,
You would need to use a macro. I have quickly penned one out for you so you can study it and adapt it to suite your needs.
| Code: | Sub Combine_Fields (oEv as object)
dim oForm
dim oControl
dim box1var as string
dim box2var as string
dim box3
dim box3var as string
dim space as string
oForm = oEv.source.model.parent
oControl = oEv.source.model
box3 = oForm.GetByName("txt_box_name_for_full_name")
box1var = oForm.GetByName("txt_box_name_for_first_name").CurrentValue
box2var = oForm.GetByName("txt_box_name_for_second_name").CurrentValue
space = " "
box3var = (box1var & space & box2var)
' msgbox box3var
box3.BoundField.updateString(box3var)
End sub |
I'm guessing you have not learnt much about macros yet. You will need to go to Tools>Macros>OrganiseMacros>OpenOrg Basic Macros. You will see "My Macros" and inside that "Standard" and "Module 1". Click on module 1 and choose edit. Paste the code from above at the bottom but leave the edit window open so you can customize it.
Now edit your form in design mode (right click and choose edit). Right click on each of your 3 text fields and select "ungroup". Now right click on the one for "first name" and choose "control". This gets you to the properties of the textbox. First select the "general" tab and take note of what the name of the text contol is including the correct case. Next click on the "events" tab and choose the event "changed" by clicking on [...] Go to where you put the macro and select it. Do the same for the "surnames" text box and also get the name of the "full_name" text box. Now you can go back to the macro and customize it with the correct text field names.
Get out of design mode of your form and you can now check to see if it works.
Have Fun
Voo |
|
| Back to top |
|
 |
etho201 Newbie

Joined: 29 Apr 2008 Posts: 2
|
Posted: Wed Apr 30, 2008 6:39 am Post subject: |
|
|
Ok, first off... Thank you so much for being so descriptive! It's very helpful!
I can't figure out what oEv.source.model.parent & oEv.source.model are...
And I went to Form Navigator to find out what some things were called... and I assume that where you put oForm... mine is probably MainForm.
To keep it simple... Right now I am just trying to make what I put in txtname to go into txtmeta_title.. and is what I have so far but I am getting some errors...
| Code: | Sub Combine_Fields (oEv as object)
dim MainForm
dim txtname as string
dim txtmeta_title as string
dim box3
dim box3var as string
dim space as string
txtname = MainForm.GetByName("txtname")
txtmeta_title = (txtname)
End sub |
|
|
| Back to top |
|
 |
Voobase OOo Advocate


Joined: 21 Nov 2007 Posts: 400 Location: Australia
|
Posted: Wed Apr 30, 2008 7:28 am Post subject: |
|
|
Hi again,
| Quote: | | I can't figure out what oEv.source.model.parent & oEv.source.model are... |
It's a bit tricky to explain (and i'm still learning too) about oEv etc but here goes... You might have noticed on the top line (oEv as object). This section is for passing something onto the sub routine and in this case it is an "object" from the control (text box) that called the macro. What is an object?... well yes. Something to do with the API of base, like the path or parameters that the control contains. oEv is the variable that gets assigned and could be anything. You will often see people use "oEvent" or "Event" instead.
Doing this allows a reference point of types, so you can then navigate through the heir achy of properties and methods that the controls and forms contain. You don't then actually have to know what the form is called as you are getting to all the properties via the control (text box) that used its event to trigger the macro.
The best way to see this when writing macros is to use a tool called XRay which you will find if you do a search. This tool allows you to write in your macro something like "XRAY oEv.source.model" which, in this case will display all the parameters of the textbox that called it (and there are many more than what you see when just browsing the properties using design mode).
| Quote: | | And I went to Form Navigator to find out what some things were called... and I assume that where you put oForm... mine is probably MainForm. |
No, as I said just above, you don't need to know the name of your form at this time.
If the event that triggered the macro came from a control (such as a text box) the path to its properties is oEv.source.model. If you want to get to the properties of the form that the control sits in, then it would be oEv.source.model.parent. ("control sits in" being the operative words here!)
Slightly differently, if it was the form that triggered the event that calls the macro, then the path to the form properties would be just oEv.source. If you then wanted to get to the control's properties, again it is different and you would use oEv.source.GetByName("Name_of_your_control")
In short, just leave the oEv.source.model stuff for now and only substitute in the names of your text box's. I know its a bit to digest. Hope my explanation hasn't been too confusing.
Cheers
Voo |
|
| Back to top |
|
 |
|