MS Access Form textbox calculations using VBA

lokuwel

New member
Local time
Today, 17:01
Joined
Mar 28, 2020
Messages
4
Hi
I need your help to find solution for this;
I need to multiply text6 and text4 in my ms access form.And the result should show inside the text8

For example it should be like this;
text8.val = text4.val * text6.val

I need to do this using vba code.And text8 value should update automatically.(may me textbox8 under event = change,but I do not know exactly)
Specially I need to do this using VBA coding only.

Thank you
 
In the control source for text8 do this;

= text4 * text6

No need for any VBA.
 
Unverified, but I am pretty sure in an expression bracketing is required.
= [text4] * [text6]
 
I need vba code because I want to add that value to linked table.If I add that using control source how I save that value to the linked table.Please see attached screen shot.
 
in vba it would be

text8 = text4 * text6

and suggest you put the code in the following events

form current event
text4 afterupdate event
text6 afterupdate event

however with a few exceptions (this might be one?) it is not good practice to store calculated values but better to calculate as and when required.
 
In the control source for text8 do this;

= text4 * text6

No need for any VBA.
If I add this using control source is it possible to pass the result to linked table.If I add this to control source how I should I bound the textbox8 with table column?
 
As CJ has said, if you can always calculate it then you shouldn't store it.
If you need to store it then his code will do it, if it that field is available on the form. If not it gets more complicated.

And @MajP is correct you need the bracketing (in fact Access adds the brackets automagically...!)
= [text4] * [text6]
 
I'll add this warning: If you are going to do this, you need to protect it against situations where one of those items is empty or null. You might get errors in such cases.
 

Users who are viewing this thread

Back
Top Bottom