Automatic totals (1 Viewer)

Ravi Kumar

Registered User.
Local time
Tomorrow, 03:30
Joined
Aug 22, 2019
Messages
162
hello all,
I have a form called usage of gauges,
In it i will enter the number of times i have used the gauge today ,
but this must be added to the table named same as my form & store the new value.
for example: if in my form i enter position = 36,
suppose the column field contained 24 earlier in my table, it should save with 60 now .
how to achieve this??
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 15:00
Joined
Aug 30, 2003
Messages
36,118
As a general rule most of us would not try to maintain the total value. We would store the transactions (24 and 36 in your example) and simply sum them with a query or DSum() as needed for forms/reports.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 18:00
Joined
Feb 19, 2002
Messages
42,976
I agree 100% with Paul. There is no way to audit a table where you can just increment the values. It is far superior to add these two as separate transactions and then sum the transactions.

However, we are looking at this request out of context and for all we know, you are trying to make a calculator. If that is the case, you would have the bound column which shows the existing value and the result after update and an unbound column in which you enter the value you want to "add" to the existing value. Then either in the AfterUpdate event of the unbound control or in the BeforeUpdate event of the form, you would add the two fields and the result gets placed in the bound field

Nz(Me.yourboundcontrol,0) + Nz(Me.yourunboundcontrol, 0)

You need the Nz() function just in case either column is null in order to avoid an arithmetic error.
 

Users who are viewing this thread

Top Bottom