AfterUpdate Add and Subtract

oxicottin

Learning by pecking away....
Local time
Today, 10:43
Joined
Jun 26, 2007
Messages
891
Hello, I have two txt boxes (txtHomeSold) and (txtHomeInvNumber) on a form and I want to be able to subtract from one another. each text box is bound to a field so I need to use the AfterUpdate event. I tried using:
Code:
Private Sub txtHomeSold_AfterUpdate()
    Me.txtHomeInvNumber = -(txtHomeSold)
End Sub
which works but it gives a - in front of the number and if I enter 0 it changes the txtHomeInvNumber to zero as well? I just want to be able to subtract each other. I included a sample. Please help.
 

Attachments

Hello, I have two txt boxes (txtHomeSold) and (txtHomeInvNumber) on a form and I want to be able to subtract from one another. each text box is bound to a field so I need to use the AfterUpdate event. I tried using:
Code:
Private Sub txtHomeSold_AfterUpdate()
    Me.txtHomeInvNumber = -(txtHomeSold)
End Sub
which works but it gives a - in front of the number and if I enter 0 it changes the txtHomeInvNumber to zero as well? I just want to be able to subtract each other. I included a sample. Please help.

Why dont you add a third text box (UNBOUND) and enter
Code:
=[txthomesold]-[txthomeinvnumber]
Then use this box to actually for whatever you want the number for.
 
these two boxes arnt the only two I have to do this to. I have two more then I need a totals. So that wont work... Thanks!
 
I assume what you're trying to do here is to subtract the number of homes sold from the number of homes in inventory, to give you the current number of homes in inventory. IF this is correct, you need:

Code:
Private Sub txtHomeSold_AfterUpdate()
  Me.txtHomeInvNumber = Me.txtHomeInvNumber - Me.txtHomeSold
End Sub

If this isn't a correct assessment of your problem you need to do a little more explaining.
 
If one wanted to do that calc before saving the record(s) and have the results be saved, would the code go in Before Update ? Or am I not understanding the op ?
 
Sure! Actually, this type of thing is usually, in fact, done in the BeforeUpdate event, although it'll be saved in either event. And this is one of those exceptions to the rule where a calculated value can to be saved.
 
Thanks
I seem to have a problem differentiating Before and After Update.
One would think they are self explanatory but....
 
Understanding the various events, how they work and the order they fire in remains one of the more esoteric aspects of Access! The Form_BeforeUpdate event has the advantage of having Cancel event available. You would always use this, for example, if you need to check that a certain field or fields had data before saving the record. If your validation code showed that data was missing, you'd use

Cancel = True

which would cancel the save operation, allowing the user to correct the problem. Checking for missing data in the Form_AfterUpdate event would be useless, because the record would have already been saved.
 

Users who are viewing this thread

Back
Top Bottom