473,473 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Updating field on a form from a sum of values field on a subforms footer.

I am having trouble working out how to update a field on an open form
with a calculation based upon calculations from other tables!
For example, I have 3 tables:
Diary
Diary_ID: autonum, primary key etc
Diary_Date: date/time
Diary_CaloriesTotal: number
Calories
Calorie_ID: autonum etc
Diary_ID: number - linked referentially to Diary.Diary_ID
Food_Lookup_ID: number lookup on food table
Calorie_Amount: number
Calorie_TotalValue: number (this is amount * food.value)
Food
Food_id: autonum etc
Food_Name: text
Food_Value: number
I have a main form for Diary and a sub form for Calories (plus a
"setup" form for food).
When you create a diary entry you can add Calorie information and in
the subform it quite happily calculates the total for each food entry
AND displays a runing total in the sub-forms footer.
However, I'd like to update Calories_Total on the Diary form with this
same running total from the sub-forms footer.
I don't mind if this is done on-the-fly or via a button etc.
I know the SQL to use in a query to ge the values, but I don't know how
to get that value in VBA to pass to the field. i.e. When I run the
SQL, how to I get a return value?
Or is there another way using queries where [Calories].[Diary_ID] =
[!forms].[diary].[diary_id]
[As additional information: In the future I'll have forms for using
calories too, so want to have a total used, total eaten and then the
net total on the diary form]
Thanks for any assistance.


Jan 23 '06 #1
1 1636
Chippy wrote:
I am having trouble working out how to update a field on an open form
with a calculation based upon calculations from other tables!
For example, I have 3 tables:
Diary
Diary_ID: autonum, primary key etc
Diary_Date: date/time
Diary_CaloriesTotal: number
Calories
Calorie_ID: autonum etc
Diary_ID: number - linked referentially to Diary.Diary_ID
Food_Lookup_ID: number lookup on food table
Calorie_Amount: number
Calorie_TotalValue: number (this is amount * food.value)
Food
Food_id: autonum etc
Food_Name: text
Food_Value: number
I have a main form for Diary and a sub form for Calories (plus a
"setup" form for food).
When you create a diary entry you can add Calorie information and in
the subform it quite happily calculates the total for each food entry
AND displays a runing total in the sub-forms footer.
However, I'd like to update Calories_Total on the Diary form with this
same running total from the sub-forms footer.
I don't mind if this is done on-the-fly or via a button etc.
I know the SQL to use in a query to ge the values, but I don't know how
to get that value in VBA to pass to the field. i.e. When I run the
SQL, how to I get a return value?
Or is there another way using queries where [Calories].[Diary_ID] =
[!forms].[diary].[diary_id]
[As additional information: In the future I'll have forms for using
calories too, so want to have a total used, total eaten and then the
net total on the diary form]
Thanks for any assistance.


I'll assume you store the calculated value Calorie_TotalValue in the
table Calories. If so, then in the Form_AfterUpdate event of the
Caleries subform you could enter something like

Forms!Diary!Diary_CaloriesTotal = _
NZ(DSum("Calorie_TotalValue","Calories", _
"DiaryID = " & Me.DiaryID),0)
Jan 24 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? ...
3
by: MX1 | last post by:
I have a query written in MS Access that has a few calculated fields. Is it possible to refer to that query in a form field. I'd like the form field to show the sum of one of the columns from the...
2
by: chris vettese | last post by:
I've been having trouble with this for a long time. I have a form that has many subforms. In the subforms I have unbound text boxes in the footer that sum a field. I want to Display this sum on...
2
by: Claude | last post by:
Let' say we have an application for a production facility running 24/7 broken into 3 shifts 6-2,2-10,10-6 each production report date contains 3 shifts as above in each shift there can be from...
5
by: Richard Stanton | last post by:
Hello all My database has a main form linked to table1. It has several subforms on the main form, all linked to table2. Table1 and Table2 are linked by primary/foreign key, no duplicates...
2
by: Chippy | last post by:
I am having trouble working out how to update a field on an open form with a calculation based upon calculations from other tables! For example, I have 3 tables: Diary Diary_ID: autonum,...
8
by: bassamsuha | last post by:
Hi, I have 2 subforms in my main form each of them has its own Autoincrement ID number. When I try to add new record and filling table fields It showing me an error :The changes you requested to...
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
6
by: Richard Penfold | last post by:
Can someone explain why a field on the many side of a one-to-many relationship, with referential integrity enforced, is not automatically updating? I have 5 tables in my database with the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.