A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Have Fields Automatically Calculate



 
 
Thread Tools Display Modes
  #1  
Old July 11th, 2008, 03:35 AM posted to microsoft.public.access.gettingstarted
NickW
external usenet poster
 
Posts: 14
Default Have Fields Automatically Calculate

I would like to have a field add numbers from two other fields. so
Total= subtotal1+subtotal2
I want this done at the table level. I was able to acheive this at the
form, but then it wasn't writing the value to the table.
  #2  
Old July 11th, 2008, 04:40 AM posted to microsoft.public.access.gettingstarted
Arvin Meyer [MVP]
external usenet poster
 
Posts: 4,231
Default Have Fields Automatically Calculate

Since a query, form, or report can re-calculate this at any time, there is
no reason to store the calculated value. It is also a violation of database
normalization rules.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


"NickW" wrote in message
...
I would like to have a field add numbers from two other fields. so
Total= subtotal1+subtotal2
I want this done at the table level. I was able to acheive this at the
form, but then it wasn't writing the value to the table.



  #3  
Old July 11th, 2008, 12:34 PM posted to microsoft.public.access.gettingstarted
John Spencer
external usenet poster
 
Posts: 7,815
Default Have Fields Automatically Calculate

Plus Access does not support this at the table level. If you really feel you
HAVE to do this, you will have to do it at the data entry level of a form.

If someone ever modifies the component parts using a query or direct entry
into a table (or a query) the total will be inaccurate. So Arvin Meyer's
suggestion of recalculating the total when needed is the correct way to handle
this.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

Arvin Meyer [MVP] wrote:
Since a query, form, or report can re-calculate this at any time, there is
no reason to store the calculated value. It is also a violation of database
normalization rules.

  #4  
Old July 11th, 2008, 03:05 PM posted to microsoft.public.access.gettingstarted
NickW
external usenet poster
 
Posts: 14
Default Have Fields Automatically Calculate

Okay. Well, i was able to get the data to show in a text box by having the
control source be the sum of two fields, but then how do I write this to the
table? When I went into the table, there was no data in the product field

"John Spencer" wrote:

Plus Access does not support this at the table level. If you really feel you
HAVE to do this, you will have to do it at the data entry level of a form.

If someone ever modifies the component parts using a query or direct entry
into a table (or a query) the total will be inaccurate. So Arvin Meyer's
suggestion of recalculating the total when needed is the correct way to handle
this.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

Arvin Meyer [MVP] wrote:
Since a query, form, or report can re-calculate this at any time, there is
no reason to store the calculated value. It is also a violation of database
normalization rules.


  #5  
Old July 11th, 2008, 04:52 PM posted to microsoft.public.access.gettingstarted
John Spencer
external usenet poster
 
Posts: 7,815
Default Have Fields Automatically Calculate

Again, I stress that you should not record the total in the table at all.

But, since you seem determined to do so,

REMOVE the formula from the textbox.
Set the textbox control source to the name of the field you want to store the
amount.

On the two controls that contain the information you are adding together, use
the after update event and add code that looks something like the following.

Private Sub tAmount1_AfterUpdate()
Me.someTotalControl = Me.tAmount1 + Me.tAmount2
End Sub

Private Sub tAmount2_AfterUpdate()
Me.someTotalControl = Me.tAmount1 + Me.tAmount2
End Sub

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

NickW wrote:
Okay. Well, i was able to get the data to show in a text box by having the
control source be the sum of two fields, but then how do I write this to the
table? When I went into the table, there was no data in the product field

"John Spencer" wrote:

Plus Access does not support this at the table level. If you really feel you
HAVE to do this, you will have to do it at the data entry level of a form.

If someone ever modifies the component parts using a query or direct entry
into a table (or a query) the total will be inaccurate. So Arvin Meyer's
suggestion of recalculating the total when needed is the correct way to handle
this.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

Arvin Meyer [MVP] wrote:
Since a query, form, or report can re-calculate this at any time, there is
no reason to store the calculated value. It is also a violation of database
normalization rules.

  #6  
Old July 11th, 2008, 05:11 PM posted to microsoft.public.access.gettingstarted
gls858
external usenet poster
 
Posts: 473
Default Have Fields Automatically Calculate

John Spencer wrote:
Again, I stress that you should not record the total in the table at all.

But, since you seem determined to do so,

REMOVE the formula from the textbox.
Set the textbox control source to the name of the field you want to
store the amount.

On the two controls that contain the information you are adding
together, use the after update event and add code that looks something
like the following.

Private Sub tAmount1_AfterUpdate()
Me.someTotalControl = Me.tAmount1 + Me.tAmount2
End Sub

Private Sub tAmount2_AfterUpdate()
Me.someTotalControl = Me.tAmount1 + Me.tAmount2
End Sub

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

NickW wrote:
Okay. Well, i was able to get the data to show in a text box by
having the control source be the sum of two fields, but then how do I
write this to the table? When I went into the table, there was no
data in the product field

"John Spencer" wrote:

Plus Access does not support this at the table level. If you really
feel you HAVE to do this, you will have to do it at the data entry
level of a form.

If someone ever modifies the component parts using a query or direct
entry into a table (or a query) the total will be inaccurate. So
Arvin Meyer's suggestion of recalculating the total when needed is
the correct way to handle this.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

Arvin Meyer [MVP] wrote:
Since a query, form, or report can re-calculate this at any time,
there is no reason to store the calculated value. It is also a
violation of database normalization rules.


OP will probably be back later asking why the stored values aren't
accurate :-)

gls858
  #7  
Old July 11th, 2008, 05:35 PM posted to microsoft.public.access.gettingstarted
Stockwell43
external usenet poster
 
Posts: 579
Default Have Fields Automatically Calculate

Hi Arvin,

I was wondering if you could help me with a situation. I downloaded your
EmailSenate2k database and notice if I selction an email address and click
the email button it works fine but if I deselect that same email address so
nothing is selected I get an error. Is there a fix so if the user selects an
email address and decides that was not the right one and deselects they won't
get the error message? I'd like to use this in my database but afraid of
users getting the error and messing around with the code.

Thanks!!

"Arvin Meyer [MVP]" wrote:

Since a query, form, or report can re-calculate this at any time, there is
no reason to store the calculated value. It is also a violation of database
normalization rules.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


"NickW" wrote in message
...
I would like to have a field add numbers from two other fields. so
Total= subtotal1+subtotal2
I want this done at the table level. I was able to acheive this at the
form, but then it wasn't writing the value to the table.




  #8  
Old July 11th, 2008, 09:19 PM posted to microsoft.public.access.gettingstarted
Arvin Meyer [MVP]
external usenet poster
 
Posts: 4,231
Default Have Fields Automatically Calculate

I see your problem. My code assumes that there will always be someone to
send the email to. Adding an If ... Then statement will fix that:

Private Sub lstMailTo_Click()
Dim varItem As Variant
Dim strList As String

With Me!lstMailTo
If .MultiSelect = 0 Then
Me!txtSelected = .Value
Else
For Each varItem In .ItemsSelected
strList = strList & .Column(0, varItem) & ";"
Next varItem
If Len(strList) 1 Then
strList = Left$(strList, Len(strList) - 1)
End If
Me!txtSelected = strList
End If
End With
End Sub

This is what was added:

If Len(strList) 1 Then

End If
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

"Stockwell43" wrote in message
news
Hi Arvin,

I was wondering if you could help me with a situation. I downloaded your
EmailSenate2k database and notice if I selction an email address and click
the email button it works fine but if I deselect that same email address
so
nothing is selected I get an error. Is there a fix so if the user selects
an
email address and decides that was not the right one and deselects they
won't
get the error message? I'd like to use this in my database but afraid of
users getting the error and messing around with the code.

Thanks!!

"Arvin Meyer [MVP]" wrote:

Since a query, form, or report can re-calculate this at any time, there
is
no reason to store the calculated value. It is also a violation of
database
normalization rules.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


"NickW" wrote in message
...
I would like to have a field add numbers from two other fields. so
Total= subtotal1+subtotal2
I want this done at the table level. I was able to acheive this at the
form, but then it wasn't writing the value to the table.






  #9  
Old July 11th, 2008, 09:29 PM posted to microsoft.public.access.gettingstarted
Stockwell43
external usenet poster
 
Posts: 579
Default Have Fields Automatically Calculate

Works great!!!

Thank you Arvin, your was most appreciate!!!

"Arvin Meyer [MVP]" wrote:

I see your problem. My code assumes that there will always be someone to
send the email to. Adding an If ... Then statement will fix that:

Private Sub lstMailTo_Click()
Dim varItem As Variant
Dim strList As String

With Me!lstMailTo
If .MultiSelect = 0 Then
Me!txtSelected = .Value
Else
For Each varItem In .ItemsSelected
strList = strList & .Column(0, varItem) & ";"
Next varItem
If Len(strList) 1 Then
strList = Left$(strList, Len(strList) - 1)
End If
Me!txtSelected = strList
End If
End With
End Sub

This is what was added:

If Len(strList) 1 Then

End If
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

"Stockwell43" wrote in message
news
Hi Arvin,

I was wondering if you could help me with a situation. I downloaded your
EmailSenate2k database and notice if I selction an email address and click
the email button it works fine but if I deselect that same email address
so
nothing is selected I get an error. Is there a fix so if the user selects
an
email address and decides that was not the right one and deselects they
won't
get the error message? I'd like to use this in my database but afraid of
users getting the error and messing around with the code.

Thanks!!

"Arvin Meyer [MVP]" wrote:

Since a query, form, or report can re-calculate this at any time, there
is
no reason to store the calculated value. It is also a violation of
database
normalization rules.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


"NickW" wrote in message
...
I would like to have a field add numbers from two other fields. so
Total= subtotal1+subtotal2
I want this done at the table level. I was able to acheive this at the
form, but then it wasn't writing the value to the table.






  #10  
Old July 11th, 2008, 09:31 PM posted to microsoft.public.access.gettingstarted
Stockwell43
external usenet poster
 
Posts: 579
Default Have Fields Automatically Calculate

By the way, it's a very useful piece you created and quite helpful.

Thanks!

"Arvin Meyer [MVP]" wrote:

I see your problem. My code assumes that there will always be someone to
send the email to. Adding an If ... Then statement will fix that:

Private Sub lstMailTo_Click()
Dim varItem As Variant
Dim strList As String

With Me!lstMailTo
If .MultiSelect = 0 Then
Me!txtSelected = .Value
Else
For Each varItem In .ItemsSelected
strList = strList & .Column(0, varItem) & ";"
Next varItem
If Len(strList) 1 Then
strList = Left$(strList, Len(strList) - 1)
End If
Me!txtSelected = strList
End If
End With
End Sub

This is what was added:

If Len(strList) 1 Then

End If
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

"Stockwell43" wrote in message
news
Hi Arvin,

I was wondering if you could help me with a situation. I downloaded your
EmailSenate2k database and notice if I selction an email address and click
the email button it works fine but if I deselect that same email address
so
nothing is selected I get an error. Is there a fix so if the user selects
an
email address and decides that was not the right one and deselects they
won't
get the error message? I'd like to use this in my database but afraid of
users getting the error and messing around with the code.

Thanks!!

"Arvin Meyer [MVP]" wrote:

Since a query, form, or report can re-calculate this at any time, there
is
no reason to store the calculated value. It is also a violation of
database
normalization rules.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


"NickW" wrote in message
...
I would like to have a field add numbers from two other fields. so
Total= subtotal1+subtotal2
I want this done at the table level. I was able to acheive this at the
form, but then it wasn't writing the value to the table.






 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:22 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.