Get the value (average) of 4 text boxes and save to DB (1 Viewer)

Josh011384

New member
Local time
Today, 08:47
Joined
Jul 16, 2017
Messages
3
I have this problem since 3 days,

Trying to get the average value of 4 text boxes and save them to database,

i write this in control source of where i want to see the value, although it works but it never save the value in my DB
=Sum([textboxA]+[textboxB]+[textboxC]+[textboxD])/4

questions are;

where do i have to write the code (in event)?

will it save the value in my DB and update the form real-time based on the value of source text boxes?

Thank you in advance guys...
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 01:47
Joined
Jan 20, 2009
Messages
12,851
If the values in the textboxes are stored in the database you would not store their average too, but calculate and display it as required from the original data, exactly as you have with the control source.

Otherwise, there are several different ways to store the average. The trick is the action needs to be triggered by some event. BeforeUpdate Event could be used to write the calculation to a bound textbox.
 

Josh011384

New member
Local time
Today, 08:47
Joined
Jul 16, 2017
Messages
3
To Galaxiom,

Thank you for the reply, i did try to write the code me.textboxA.Val + me.textboxB.Val, but i didn't get the result i want

Can you help me with this code and give me an example?

TIA
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 01:47
Joined
Jan 20, 2009
Messages
12,851
Code:
With Me
     .textboxAvg = (.txtboxA + .textboxB + .textboxC + .textboxD)/4
End With
Val is not a property of a Textbox. Value is, but since it is the default property it can be omitted.

You will get problems if any are blank.
 

Users who are viewing this thread

Top Bottom