On Sat, Dec 12, 2009 at 5:42 AM, Andreas Saeger <[email protected]>wrote:
> Michael Hunold wrote: > >> Hello all, >> >> http://www.mihu.de/foo.odb >> >> In my sample database "foo.odb" I have created a table "foo", with >> fields "nr" (primary key, auto-increment) and "foo" (integer). >> >> Then I added a query "sum_of_foo", which, well, calculates the sum of >> field "foo". >> >> Then I created a form "from". This has a table control which references >> to table "foo". Next I created a subform below the main form and >> connected it to "sum_of_foo". Then I added a formatted field and made it >> display the "sum_of_foo". >> >> Now when I open up the form, I can see the entries in the top and the >> formatted field shows the sum of row "foo". When I change entries and >> press "Enter", the sum is updated accordingly. >> >> But, when you move the cursor to the row with the "Star" so that you can >> add a new record, then the sum vanishes from the formatted field. >> >> Is this a bug or a feature? Did I do something wrong when setting up the >> subform or the query? >> >> > A subform shows some data (calculated or not) that relate to the parent > form through some common field(s). > For instance: parent form shows some article, subform shows the sum of all > sales having the same article-ID as the parent form's currently selected > article. > While entering a new article into the parent form, the subform does not get > any article ID until the parent form's new record has been stored to disk. > > Hello Michael Andreas is correct in describing how a sub-form behaves - the situation is however, given the description of what Michael wants to achieve, that no sub-form should be used at all. In many form designers there is a root result set - Base does not have this constraint. There is no requirement that all dataform controls (these represent the result set) be nested, one under the other. So - taking your example database I made a couple of small changes. First - just for clarity - I renamed your two dataform controls to be "foo" and "sum_foo". Second - break the link between the two dataform controls, so that they are peers. Third - add a one line macro that will update the result set for sum_foo whenever a record is edited, inserted or deleted from foo. The updated file is attached to this email. Open the form and edit the data in the table, you should see the value in the sum field change as you want it to. Drew
foo.odb
Description: application/vnd.oasis.opendocument.database
--------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
