Calculated fields

L

LindaBee

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!!!
 
D

Danny Lesandrini

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.
 
L

LindaBee

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?
 
K

Keith Wilby

LindaBee said:
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
 
L

LindaBee

Its sorted now thanks for all responses

Keith Wilby said:
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
 

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

Top