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 » Database Design
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Calculated fields



 
 
Thread Tools Display Modes
  #1  
Old February 5th, 2009, 11:19 AM posted to microsoft.public.access.tablesdbdesign
LindaBee
external usenet poster
 
Posts: 52
Default Calculated fields

Hi All
I have a puzzling problem and I cannot figure out where I am going wrong
perhaps the experts can help me out here!

I have created a form in my database that calculates payment based on the
value in one field. I have a field called Question1A and a Text field called
Text1A I enter a value in Question1A and the calcualtions are displayed in
Text1A and the I have 2 ore fields Question2B and Text2B the combined values
in Question1A and Question1B calculate This works ok except when I enter a
new record the values from the previous record are displayed and I have to
refresh the screen for the default values to be displayed.

I have tried enterring the calculations in the before and after update and
on form load

Question1A and Question1B are both manual entries by user

here is a sample of the code


The first function calculates what goes into Text1A

Private Sub Question1A_BeforeUpdate(Cancel As Integer)

If Me.Question1A = "A" Then
Me.Text1A = 12* 0
Else
If Me.Question1A = "B" Then
Me.Text1A = 12* 0.5 * 3
Else
If Me.Question1A = "C" Then
Me.Text1A = CalculatorField * 4 * 0.5
Else
End If
End If
End If

what goes into Text1B

Private Sub Question1B_BeforeUpdate(Cancel As Integer)
If Me.Question1A = "A" And Me.Question1B = "1" Then
Me.Text1B = Me.Text1A * 2
Else
If Me.Question1A = "A" And Me.Question1B = "2" Then
Me.Text1B = Me.Text1A * 4
ElseIf Me.Question1A = "B" And Me.Question1B = "1" Then
Me.Text1B = Me.Text1A * 6
Else
If Me.Question1A = "B" And Me.Question1B = "2" Then
Me.Text1B = Me.Text1A * 8
Else
End If
End If
End If


Please please HELP!!!

  #2  
Old February 5th, 2009, 02:01 PM posted to microsoft.public.access.tablesdbdesign
Danny Lesandrini
external usenet poster
 
Posts: 109
Default Calculated fields

LindaBee, I'm having a hard time following this but if your issue is one of
refreshing, then try this. Duplicate the calculation code in the OnCurrent
event. That will refresh the calculated fields when you navigate to a new
record.
--
Danny J Lesandrini

www.amazecreations.com



"LindaBee" wrote ...
Hi All
I have a puzzling problem and I cannot figure out where I am going wrong
perhaps the experts can help me out here!

I have created a form in my database that calculates payment based on the
value in one field. I have a field called Question1A and a Text field called
Text1A I enter a value in Question1A and the calcualtions are displayed in
Text1A and the I have 2 ore fields Question2B and Text2B the combined values
in Question1A and Question1B calculate This works ok except when I enter a
new record the values from the previous record are displayed and I have to
refresh the screen for the default values to be displayed.

I have tried enterring the calculations in the before and after update and
on form load

Question1A and Question1B are both manual entries by user

here is a sample of the code


The first function calculates what goes into Text1A

Private Sub Question1A_BeforeUpdate(Cancel As Integer)

If Me.Question1A = "A" Then
Me.Text1A = 12* 0
Else
If Me.Question1A = "B" Then
Me.Text1A = 12* 0.5 * 3
Else
If Me.Question1A = "C" Then
Me.Text1A = CalculatorField * 4 * 0.5
Else
End If
End If
End If

what goes into Text1B

Private Sub Question1B_BeforeUpdate(Cancel As Integer)
If Me.Question1A = "A" And Me.Question1B = "1" Then
Me.Text1B = Me.Text1A * 2
Else
If Me.Question1A = "A" And Me.Question1B = "2" Then
Me.Text1B = Me.Text1A * 4
ElseIf Me.Question1A = "B" And Me.Question1B = "1" Then
Me.Text1B = Me.Text1A * 6
Else
If Me.Question1A = "B" And Me.Question1B = "2" Then
Me.Text1B = Me.Text1A * 8
Else
End If
End If
End If


Please please HELP!!!



  #3  
Old February 5th, 2009, 03:32 PM posted to microsoft.public.access.tablesdbdesign
LindaBee
external usenet poster
 
Posts: 52
Default Calculated fields

Hi Danny
Thanks for the response but I tried this and am still getting values in some
fields.

I have clculated fields which are updated depending on avlues entered in
boud fields. What is hapenning is that when I try to create a new record the
calculated values in teh previous record are being carried into the new
record, in other words instead of displaying the default value 0 I am getting
whatever figure was in the previous record.

Does this make sense?
"Danny Lesandrini" wrote:

LindaBee, I'm having a hard time following this but if your issue is one of
refreshing, then try this. Duplicate the calculation code in the OnCurrent
event. That will refresh the calculated fields when you navigate to a new
record.
--
Danny J Lesandrini

www.amazecreations.com



"LindaBee" wrote ...
Hi All
I have a puzzling problem and I cannot figure out where I am going wrong
perhaps the experts can help me out here!

I have created a form in my database that calculates payment based on the
value in one field. I have a field called Question1A and a Text field called
Text1A I enter a value in Question1A and the calcualtions are displayed in
Text1A and the I have 2 ore fields Question2B and Text2B the combined values
in Question1A and Question1B calculate This works ok except when I enter a
new record the values from the previous record are displayed and I have to
refresh the screen for the default values to be displayed.

I have tried enterring the calculations in the before and after update and
on form load

Question1A and Question1B are both manual entries by user

here is a sample of the code


The first function calculates what goes into Text1A

Private Sub Question1A_BeforeUpdate(Cancel As Integer)

If Me.Question1A = "A" Then
Me.Text1A = 12* 0
Else
If Me.Question1A = "B" Then
Me.Text1A = 12* 0.5 * 3
Else
If Me.Question1A = "C" Then
Me.Text1A = CalculatorField * 4 * 0.5
Else
End If
End If
End If

what goes into Text1B

Private Sub Question1B_BeforeUpdate(Cancel As Integer)
If Me.Question1A = "A" And Me.Question1B = "1" Then
Me.Text1B = Me.Text1A * 2
Else
If Me.Question1A = "A" And Me.Question1B = "2" Then
Me.Text1B = Me.Text1A * 4
ElseIf Me.Question1A = "B" And Me.Question1B = "1" Then
Me.Text1B = Me.Text1A * 6
Else
If Me.Question1A = "B" And Me.Question1B = "2" Then
Me.Text1B = Me.Text1A * 8
Else
End If
End If
End If


Please please HELP!!!




  #4  
Old February 5th, 2009, 03:46 PM posted to microsoft.public.access.tablesdbdesign
Keith Wilby
external usenet poster
 
Posts: 812
Default Calculated fields

"LindaBee" wrote in message
...
Hi Danny
Thanks for the response but I tried this and am still getting values in
some
fields.

I have clculated fields which are updated depending on avlues entered in
boud fields. What is hapenning is that when I try to create a new record
the
calculated values in teh previous record are being carried into the new
record, in other words instead of displaying the default value 0 I am
getting
whatever figure was in the previous record.


You could always do the calculations in the form's query. You could use
either the "Iif" function or write your own (similar to the code you already
have) and pass the fields from the query to it as arguments.

Keith.
www.keithwilby.co.uk

  #5  
Old February 5th, 2009, 04:13 PM posted to microsoft.public.access.tablesdbdesign
LindaBee
external usenet poster
 
Posts: 52
Default Calculated fields

Its sorted now thanks for all responses

"Keith Wilby" wrote:

"LindaBee" wrote in message
...
Hi Danny
Thanks for the response but I tried this and am still getting values in
some
fields.

I have clculated fields which are updated depending on avlues entered in
boud fields. What is hapenning is that when I try to create a new record
the
calculated values in teh previous record are being carried into the new
record, in other words instead of displaying the default value 0 I am
getting
whatever figure was in the previous record.


You could always do the calculations in the form's query. You could use
either the "Iif" function or write your own (similar to the code you already
have) and pass the fields from the query to it as arguments.

Keith.
www.keithwilby.co.uk


 




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 06:59 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.