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

Joined: 30 Apr 2008 Posts: 30
|
Posted: Sat Oct 11, 2008 7:38 am Post subject: adding 2 fields in a form |
|
|
I have a form based on a table. Relevant fields are Expense, GST, PST an Total. The first 3 fields are from the table, the Total field is not tied to a table. The first 3 fields are Formatted fields, the Total field is a numeric field.
I have a macro specified in Form Events, When Loading, but the Total field does not show the total.
Thanks for your help
Bart
REM ***** BASIC *****
Sub calcTotal(event As Object)
On Error Goto HandleErr
Dim Form As Object
Dim Ctrl1 As Double
Dim Ctrl2 As Double
Dim Ctrl3 As Double
rem Double
Form=event.Source.getModel().getParent()
Ctrl1=Form.getByName("Expense").Text
Ctrl2=Form.getByName("PST").Text
Ctrl3=Form.getByName("GST").Text
Form.getByName("Total").Text=Ctrl1+Ctrl2+Ctrl3
HandleErr:
Exit Sub
End Sub |
|
| Back to top |
|
 |
marc_ly General User

Joined: 11 Oct 2008 Posts: 5
|
Posted: Sat Oct 11, 2008 1:48 pm Post subject: |
|
|
I threw together a quick database with the most generic of what you were talking about: Expense, PST, GST, Total each as Doubles in the table and then generating a form from the wizard
Then in the form I put this Sub in each box I was entering info into so it would update after each entry.
'#######################################################
'# calcTotal Adding up text fields
'#######################################################
'# This is placed in the When Losing focus event in each
'# numeric box so it would update after i enter each amount
Sub calcTotal(event As Object)
Dim ExpAmt as Double, PSTAmt as Double, GSTAmt as Double, TtlAmt as Double
Dim Form_model
Form_model=Event.Source.Model.Parent
'# This fmt part is an addition Base puts on form boxes
ExpAmt=Form_model.getByName("fmtExpense").getCurrentValue
PSTAmt=Form_model.getByName("fmtPST").getCurrentValue
GSTAmt=Form_model.getByName("fmtGST").getCurrentValue
TtlAmt=ExpAmt+PSTAmt+GSTAmt
Form_model.getByName("fmtTOTAL").BoundField.updateDouble(TtlAmt)
End Sub
It seemed to work perfectly for me. Hope it works for you too.
Marc |
|
| Back to top |
|
 |
MSPhobe OOo Advocate

Joined: 29 Sep 2005 Posts: 465 Location: England
|
Posted: Sat Oct 11, 2008 2:03 pm Post subject: |
|
|
Another... simpler?.... way to get a form to display the sum (or other mathematical combination) of the data in some of the other fields displayed on the form is explained at....
http://sheepdogguides.com/fdb/fdb1calcf1.htm
(I hope I am right in inferring that you only want the sum of the figures showing on the form, not some kind of total involving values from multiple RECORDS? (If not, the tutorial mentioned is of No Use!) |
|
| Back to top |
|
 |
Bucky10 General User

Joined: 30 Apr 2008 Posts: 30
|
Posted: Sun Oct 12, 2008 6:38 am Post subject: |
|
|
Thanks Marc & Msphobe
Marc, your solution is based on control events.
I want the total to show when the form is opened, and each time the user goes to a new record. So I am looking for a form based macro solution.
Msphobe,
the reference features a query. I know how to do the math in a query, but now I am very confused. The author goes on to create a form based on the query and SAYS changes you make to the data "percolate" back to the table. THIS HAS BEEN MY STRUGGLE FROM THE BEGINNING, forms I create based on a query do not allow me to edit the data. Posts to this forum for a solution result in answers like "base your form on a table". But the only way to add two fields with a form based on a table is with a macro.
Msphobe am I going insane?
ooBase designers listen... in my old dos based db program, all I had to do was put "=abc+xzy" into the source of a form control, and bingo!
Bart |
|
| Back to top |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 1716 Location: Apeldoorn, Netherland
|
Posted: Sun Oct 12, 2008 8:00 am Post subject: |
|
|
Hello
Maybe this code is wahat you need. You have to adjust it for an event. Is it not what you need describe it better
| Quote: | ooBase designers listen... in my old dos based db program, all I had to do was put "=abc+xzy" into the source of a form control, and bingo!
|
And let we hope that the designers spent there time better then reading this.
Romke
| Code: |
Sub calcTotal
Dim Form As Object
Dim Ctrl1 As Double
Dim Ctrl2 As Double
Dim Ctrl3 As Double
rem Double
'Form=event.Source.getModel().getParent()
form = thiscomponent.drawpage.forms.getbyname("Standard")
Ctrl1=Form.getByName("Expense").value
Ctrl2=Form.getByName("PST").text
Ctrl3=Form.getByName("GST").value
'use text for a text field and value for an nummeric field
print Ctrl1 +Ctrl2 +Ctrl3
Form.getByName("Total").value=Ctrl1+Ctrl2+Ctrl3
HandleErr:
Exit Sub
End Sub
|
|
|
| Back to top |
|
 |
MSPhobe OOo Advocate

Joined: 29 Sep 2005 Posts: 465 Location: England
|
Posted: Mon Oct 13, 2008 7:25 am Post subject: |
|
|
(Reply to question further up page....)
Are you going insane? Probably... if you are trying to get ANY computer to do ANY job! (I don't think ooBase is particularly dementia-genic, though.)
Thank you for making what you want to do so clear. It seems there OUGHT to be a way to do it. Apologies for not reading your initial post more clearly, nor checking that the "solution" offered was exactly applicable...
I'll have to see if I can do what you want, by a simple means... but it will have to be a challenge for another day... Sorry again. |
|
| Back to top |
|
 |
Bucky10 General User

Joined: 30 Apr 2008 Posts: 30
|
Posted: Sat Oct 18, 2008 7:56 am Post subject: |
|
|
Thanks Romke
I have tried this code:
| Code: | Sub test
Dim Form As Object
Dim Ctrl1 As Double
Dim Ctrl2 As Double
Dim Ctrl3 As Double
'Form=event.Source.getModel().getParent()
form = thiscomponent.drawpage.forms.getbyname("PayablesForm")
Ctrl1=Form.getByName("Expense").value
Ctrl2=Form.getByName("PST").value
Ctrl3=Form.getByName("GST").value
print Ctrl1 +Ctrl2 +Ctrl3
Form.getByName("Total").value=Ctrl1+Ctrl2+Ctrl3
End Sub |
Error | Quote: | | "BASIC runtime error, Property or method not found. |
This code is highlighted:
| Code: | | Ctrl1=Form.getByName("Expense").value |
So I changed ".value" to ".text" and the macro worked!
I am confused hy test works but value does not.
Expense, PST & GST are decimal table fields. On the form they are spec'd as Formatted Field controls. The Total control is not connected to a table, exists only to show total in the form, and is a Numeric control.
The macro works only when called manually. It is specified in the When Loading event of the form. Can you help me achieve the desired behaviour?
Many thanks,
Bart |
|
| Back to top |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 1716 Location: Apeldoorn, Netherland
|
Posted: Sat Oct 18, 2008 3:09 pm Post subject: |
|
|
Hello
Did you try the others event ?
Romke |
|
| Back to top |
|
 |
Bucky10 General User

Joined: 30 Apr 2008 Posts: 30
|
Posted: Sun Oct 19, 2008 7:11 am Post subject: |
|
|
I tried When Reloading.
This works when I press the Refresh button, BUT, jumps to the first record of the table.
I tried Before Submitting, After Resetting, & others bu did not get the desired behaviour. I tried Before Record Action which of course only works if I change a record.
In my form, the Total is to be displayed when the form is first opened, and for every record you view. To me, When Loading is the proper event to use (but does not work)
Any advice for me?
Bart
Toronto |
|
| Back to top |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 1716 Location: Apeldoorn, Netherland
|
Posted: Sun Oct 19, 2008 8:40 am Post subject: |
|
|
Hello
you say
| Quote: |
In my form, the Total is to be displayed when the form is first opened, and for every record you view. To me, When Loading is the proper event to use (but does not work) |
So I think after changing record that is I think the third from below.
Romke |
|
| Back to top |
|
 |
Bucky10 General User

Joined: 30 Apr 2008 Posts: 30
|
Posted: Sat Oct 25, 2008 5:56 am Post subject: |
|
|
Romke, I bow to your wisdom
Your suggestion has worked. I would like to blame (just a little bit) the oo Help, which is not too helpful.
There is a subform in my form, but it only displays one row.
My form content is based on my table Payables
The subform Content Type is Query
Content: Query_Payables
Query_Payables has a column with Field: "GST" + "Expense" + "PST", with Alias "Total"
Link master field is PayableID of the table, Link slave fields is "PayableID" of the query
Anyway, the subform only displays one row, how do I get it to display ALL rows?
Thx
Bart
Toronto |
|
| Back to top |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 1716 Location: Apeldoorn, Netherland
|
Posted: Sat Oct 25, 2008 12:13 pm Post subject: |
|
|
Hello
The sub form can only display those fields who belong to the query or table who is the base of the subform.
If you change the query and add more fields, you can also display more fields.
You can make the query in the grapich query designer and copy the text to the good place.
I hope this helps you
Romke |
|
| Back to top |
|
 |
Bucky10 General User

Joined: 30 Apr 2008 Posts: 30
|
Posted: Sun Oct 26, 2008 11:41 am Post subject: |
|
|
In my experience with other db front ends, the subform could be based on a different table or query based on a different table, as long as the proper ID filed can be linked.
For instance, a sales order: the form has the name, address etc, and the subform has the order items. A form should be able to show a one-to-many relationship such as this.
Are you sure about this Romke? Then why does the subform have settings for linked field? If the subform is simply a table view of the parent form, why the need to specify any linked fields?
Bart Confused
Toronto |
|
| Back to top |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 1716 Location: Apeldoorn, Netherland
|
Posted: Sun Oct 26, 2008 1:55 pm Post subject: |
|
|
Hello
| Bucky10 wrote: | | In my experience with other db front ends, the subform could be based on a different table or query based on a different table, as long as the proper ID filed can be linked. | In OOo too
| Bucky10 wrote: |
For instance, a sales order: the form has the name, address etc, and the subform has the order items. A form should be able to show a one-to-many relationship such as this. | If they have the same value. The name may differ
| Bucky10 wrote: | | Are you sure about this Romke? Then why does the subform have settings for linked field? If the subform is simply a table view of the parent form, why the need to specify any linked fields? | Maybe begin the confusing in this part. I don't know if I understand you correct. English is not my normal language.
I think that the subform is not a view of the parent form.
The link master fields points to fields in one record and the values in that record wil be used.
The link slave fields they will be used as field names in the query.
The result of that query is displayed in the subform. And a zero result is also a result
I will try give an explanation, maybe a little more then you ask.
The word form in OOo is used for two different thing
a) the writer document
b) the forms you see in the "form navigator".
And the "form navigator" is something else as the normal navigator
So you can make in the form navigator more then one form and that are not subforms. The same as in a directory in the computer. All forms can have a subform and a subform again a subform like the directory in the computer.
A form is bound to a table or query. The subform is also bound to a table or query. When you open the form, automaticaly the first record is displayed in the masterform and in the subform are displayed only those record who have the same value in the master and slave field.
If in the masterform is display something about a car with "Yellow" in the master field. In the subform will be displayed only records who have "Yellow" in the slavefield. The names of the fields may be different. If the masterfields and slavefields in the formproperties don't have values only the first record will be displayed in the subform. The subform will not follow the masterform.
This means also:
a) You can use the same table in the master form and subform ( sometimes you must give alias)
b) It may be a different table or query, what most is been done
The master and slave field make what is displayed in the subform
And for first readers. If your form or subform is based on a query then you cannot edit the form fields. If the form or subform is based on a table you can edit the form fields
I hope I have answer you question. If I have to write down those things, I must be sure that all things are correct. There I'm a home user so I learn only those things who are important for me. A professional have to learn all things
It was nice to do
Romke |
|
| Back to top |
|
 |
Bucky10 General User

Joined: 30 Apr 2008 Posts: 30
|
Posted: Sat Nov 01, 2008 9:21 am Post subject: |
|
|
Thanks Romke
I think we are on the same page.
My form is based on my table: Payables
The subform is based on my query: Query_Payables
The subform correctly displays the query data, BUT, it only displays one row.
Let me explain the use of my subform.
I want the subform to display ALL records of the Query_Payables. If select a record from the subform, I expect that record to be displayed in the main form.
Just like the accounting application we use here at work, it has a table view of records at the bottom of the window, and when I select one of the rows, it is displayed in the top of the window.
Bucky
Toronto |
|
| Back to top |
|
 |
|