After Update statement (1 Viewer)

edreamers

Registered User.
Local time
Tomorrow, 01:30
Joined
Nov 28, 2006
Messages
13
i have a problem. I want to achieve this

total2=gross_Salary+perquisites+profits
total3=house_rent+transport_allowance+others

i used AfterUpdate() function on form to do the calculation and to save the results in the table.

Private Sub grossSalary_AfterUpdate()
Me.total2 = Me.grossSalary + Me.perquistes + Me.profits
End Sub

Private Sub perquistes_AfterUpdate()
Call grossSalary_AfterUpdate
End Sub

everything is working fine till there. Now in the next fields i have to do calculation on these calculated results and save the results in table.

I want to achieve this:
Gross_taxableSalary=total2-total3

I tried to use the AfterUpdate function again, but this time its not working.
Private Sub total2_AfterUpdate()
Me.gross_taxableSalary = Me.total2 - Me.total3
End Sub

Private Sub total3_AfterUpdate()
call total2_AfterUpdate()
End Sub

Please help me. its very urgent.
 
Don't store your calculations in a table. This is a very bad idea.

Instead, create a query and create your calculated fields there (and include any other fields from your source table you might want to use). Then use this query as your data source so that your calculated fields are always available to you e.g. you can use these calculated fields in a form and they will update as you update the underlying data.

hth
Chris
 
Thanks for reply.

But is there any way through which I can achieve my goal without using query.
 
Why don't you want to use a query? That's the whole idea of a database. You'd have the whole thing done in under a minute. In case I wasn't explicit enough before, storing calculated data that can be derived is a complete no no. Nevertheless, I'll now sell my soul to the devil...

The reason it's not working is because the AfterUpdate event only fires when you change the data i.e. you change the value in the box.

So, get rid of your Total2 and Total3 events. Instead, put both calculations in the grossSalary_AfterUpdate event:

Code:
Private Sub grossSalary_AfterUpdate()
Me.total2 = Me.grossSalary + Me.perquistes + Me.profits
Me.gross_taxableSalary = Me.total2 - Me.total3
End Sub

I'm off to confession now.

Do youself a favour and write a query.

Chris
 
How could I use both query and tables for printing. we can either use table or query for one printing. My all other values stores in table. So thats why i dont want to use query because i have to print everything

Thanks for help.
 
How could I use both query and tables for printing. we can either use table or query for one printing. My all other values stores in table. So thats why i dont want to use query because i have to print everything

Thanks for help.

edreamers -

A query can be used EXACTLY in every spot a table can be used. In fact, when you look at a table in Access you aren't really looking at the table at all. You are, in fact, looking at a query that access opens to display the table data.

So, if you aren't clear on how to use queries (and this is EXTREMELY IMPORTANT if you are going to be successful in using Access) I would suggest working through this tutorial here:

http://www.functionx.com/access/Lesson17.htm

Because it will give you the knowledge you need to understand that you do not need to think in terms of should I use a table or a query, but that in most cases you will want to use queries (which can pull data together from MANY tables all at one time).
 
thanks a lot brother.

I am working on a tax calculation program. i want to use multi if statement in the manner below:-

if sex=Male
and income>110000 and income<=150000
then tax=(income-110000) *10

elseif if sex=male
and income>150000 and income<=250000
then tax=(income-150000)*20+4000

elseif sex = male
and income>250000
then tax(income-250000)*30+24000

Please tell what will be the proper syntax for this problem in access and where to write this code.

Thanks in advance.
 

Users who are viewing this thread

Back
Top Bottom