subtract 2 fields and save result in new field

ACCESS NEWB

Registered User.
Local time
Today, 23:46
Joined
Feb 12, 2008
Messages
64
HI
No need to mention that I am new in Access world.Here is my problem.I
created form in which i have to number fields START km and END km.
I would like to subtract those 2 fields and save result in same table in new fierld TOTAL
 
after update of both fields
me.totalkm=me.startkm- me.endkm
or as you have it [start km] - [end km]



as a rule don't have spaces in table/fieldnames
and steer clear of Access reserved words -start end date etc

so startkm is fine
and no numbers at the start of fields this causes problems

regards
 
The advice on Reserved Words is spot on, as is the advice about having spaces in object names. Decide on another strategy and use it consistently. Some use underlines between words, like Start_Km and End_Km, but one of the easiest to read, I think, is something like StartKm and EndKm.

If this is a distance traveled hack, like it sounds, the two values probably need to be reversed

Me.TotalKm = Me.EndKm - Me.StartKm
 
as i said im a newb
where do i enter
Me.TotalKm = Me.EndKm - Me.StartKm
(i did change names of field)
In form?
 
Along with the excellent advice you have received so far, I would add that you should not store that calculated value in your table. Simply calculate it each time you need it.
 
In the code module for your form, in the AfterUpdate events, like this:

Code:
Private Sub EndKm_AfterUpdate()
  Me.TotalKm = Me.EndKm - Me.StartKm
End Sub
Code:
Private Sub StartKm_AfterUpdate()
  Me.TotalKm = Me.EndKm - Me.StartKm
End Sub
 

Users who are viewing this thread

Back
Top Bottom