Working with tables

A

Alimbilo

I need a formula to Sum the fields of a different table to a form that needs
those data.

Example:

Form name: Books
Table1 (field: total books)
Table2 (fields: old books, new books)

In the Books form, I want Total Books from Table1 to be the Sum of table2
fields
 
E

Evi

Why do you want to store this value in a table? Each time you added or
deleted a book, the amount stored in your table would be wrong. Usually,
calculated amounts (values which can be obtained by a function like adding,
etc) are displayed using queries or reports or even text boxes in forms.
That way, they will always be up to date.

The exception to this rule would be when human intervention sets the rules
eg bulk-bought items where the more a customer buys, the less he has to pay
per unit. Since the formula for working out the discount might change at a
future date, you may need to store the current discount in some way.

The usual way to store calculations would be
1. In a report listing your books

In the report footer, you would add a text box into which you would type

=Count(OldBooks) + Count(NewBooks)


If you needed, for example, to add up these figures at the end of each week,
you would ensure that your database contained a date field and then using
the Sorting Grouping feature to do this.

2. In a query.
You would create 1 query where you add a column which says

Books::[OldBooks]+[NewBooks].
Save and close this query

Click on it, in the database window, go to Insert Query.
Add the Books field to the query grid
Click the Totals button and choose Count

The query would give you the total numbers of books.

Refinements can be made to this so that you have the totals for each
day/week/year.


If you for some reason you do need to store the value in a table then, you
would do this by using Code to run an append or update query. You would then
need additional code if someone added or deleted a book, otherwise the
stored amount would be incorrect.
But before you start learning how to do this, just check your database
design to see if you need it.

Evi
 
B

Beetle

In the Books form, I want Total Books from Table1 to be the Sum of table2

No you don't (not in the table at least). Calculated results like this
should not
be stored in tables. Do the calculation in a query, or in an unbound control
on a form or report.

While were on the subject, I don't know anything about your db, but I would
question whether you need the "old books" / "new books" fields in Table2
(assuming that those fields store the quantity of old and new books, which
is how it would appear on the surface). If you store info about books, and if
you have some type of "category" field to classify books as old or new, then
again, you can use a query to determine the quantity of old vs. new.
 
S

Stockwell43

Hi Alimbilo,

Evi is correct in the fact that you should not save information in the
table. However, you can calculate your fields on the form which would be fine
but again, if you need to view this information for multiple records, you
will need to create a report and insert the calculation there as Evi
explained.

To calculate on your form:

In your totals text box (make sure it is not bound to the table) In the
Control Source type =[NewBooks]+[OldBooks] (or whenever your field names are)
and that should do it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Please help!!! Tables 5
Excel Move or Copy Stopped Working? 0
Linking fields 1
acnewrec? 1
Fill in the blank 4
Data Collection 3
invalid syntax 5
lookup question 1

Top