Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 12th, 2003, 04:13 PM
Registered User
 
Join Date: Aug 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default updating a field populated by an expression builde

Hi

I made a table with the FF fields:
NUMBER1 NUMBER2 SUM

Then I made a form using this table. The first 2 fields are entered by the user when the user hits enter the SUM field is populated by the sum of the 2 numbers.

I made an expression builder from the control source for this SUM field: ---> = [NUMBER1] + [NUMBER2]

My problem is when I look at the table I made the first 2 fields are populated but the SUM field ( which was a result of the expression I made) wasn't. Why is this so and how do make it to automatically save this field together with the other 2 fields?

Thank you!




 
Old August 13th, 2003, 06:48 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Quote:
quote:Originally posted by jobalistic
My problem is when I look at the table I made the first 2 fields are populated but the SUM field ( which was a result of the expression I made) wasn't. Why is this so and how do make it to automatically save this field together with the other 2 fields?
To get the third field to populate, you need to put code out there. You can either put code on NUMBER2's After Update event that sums the two numbers or you can put something on the form's On Close event that sums it when you close it.

Note: It's never a good idea to store calculated fields. In this case, SUM is just NUMBER1 + NUMBER2. Don't store this because you're using up valuable memory. If you need SUM in the future, merely recalculate it. So really, the true answer to your question is don't store SUM at all! :D

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old August 13th, 2003, 10:48 AM
Registered User
 
Join Date: Aug 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Greg thank you for the reply
i know that I need to put a code in the events properties ( after update etc..) however I dont know the syntax... I know it is an update code but I am not familiar with the syntax. Would you know the code or the syntax?

I need to store the SUM field because I need to a summation on this field whenever the user inputs a value. In other words, I need to do a another calulation just for the SUM field that is why I need to store this value in the table.


 
Old August 13th, 2003, 11:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Quote:
quote:Originally posted by jobalistic
i know that I need to put a code in the events properties ( after update etc..) however I dont know the syntax... I know it is an update code but I am not familiar with the syntax. Would you know the code or the syntax?
In the After Update event use something like:
Code:
Me.[Sum Field] = Me.[No. 1 Field] + Me.[No. 2 Field]

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old August 13th, 2003, 12:21 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Originally posted by jobalistic
...
I need to store the SUM field because I need to a summation on this field whenever the user inputs a value. In other words, I need to do a another calulation just for the SUM field that is why I need to store this value in the table.
You really should read up on the concept of normalization. The first rule of normalization is that all data is atomic; that is, data is not repeated, and is not a composite made of other data elements.

The reason why this rule exists is that it is just too easy for such composite data to get 'out of sync' with the data which comprises it. If you have some process somewhere which updates, say, column NUMBER1 and doesn't 'remember' (or otherwise 'know') that NUMBER1 is not only a piece of data in its own right, but is also a component of some other column (e.g. SUM), then your data has just become corrupt. Worse, you'll have virtually no evidence that this data is wrong until somebody notices someday that things don't add up. You'll also have no idea which process or program caused the corruption or when it occurred, making for a very difficult debugging chore.

You claim you need this column because you have to sum on it, but it's a simple matter to sum the component columns as, e.g:
Code:
    SELECT SUM(Col1 + Col2) FROM ...
or otherwise include its components in any other expression.

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
 
Old August 13th, 2003, 12:59 PM
Registered User
 
Join Date: Aug 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for the Reply!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating Field in Form cthibault Access 2 January 8th, 2008 03:37 PM
Updating Last_Updated Field arholly Access 4 January 17th, 2007 12:05 PM
Updating a Date field based on another field arholly Access VBA 6 November 22nd, 2006 11:19 AM
Referring to a field and updating Programmatically vmerc Access VBA 4 January 12th, 2006 10:28 AM
sql expression field zouky Crystal Reports 0 October 29th, 2004 02:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.