How to make form populate table (1 Viewer)

Rich_B

Access Newbie
Local time
Today, 06:12
Joined
Feb 12, 2016
Messages
50
Hi

How do I get the data in a form control to populate the corresponding table field when the control source box already contains an expression for making calculations within the form?

Thank you
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:12
Joined
May 7, 2009
Messages
19,169
remove the expression from control source, instead put the expression on Default Value property. you must edit the record for it to be saved.
 

Rich_B

Access Newbie
Local time
Today, 06:12
Joined
Feb 12, 2016
Messages
50
remove the expression from control source, instead put the expression on Default Value property. you must edit the record for it to be saved.

When I do this the expression doesn't populate the cells with anything.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:12
Joined
May 7, 2009
Messages
19,169
ok on the after update event of your controls:

private sub controlName_AfterUpdate()
me.yourtextboxwithExpression = expression
end sub
 

Rich_B

Access Newbie
Local time
Today, 06:12
Joined
Feb 12, 2016
Messages
50
ok on the after update event of your controls:

private sub controlName_AfterUpdate()
me.yourtextboxwithExpression = expression
end sub

Does this look correct?

Private Sub WEIGHT_AfterUpdate()

Me.WEIGHT = IIf([WEIGHT CALC] <> "0", ([H] * [W] * [L] * [WEIGHT CALC] / 1000000000), "-")

End Sub

WEIGHT is the name of the textbox

Thank you
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:12
Joined
May 7, 2009
Messages
19,169
yes, do it also to the rest of your control's after update (if you have, ie H, L, W).
wait, you cant do arithmetics with string:

Me.WEIGHT = IIf([WEIGHT CALC] <> "0", ([H] * [W] * [L] * [WEIGHT CALC] / 1000000000), "-")

should be:

Me.WEIGHT = IIf([WEIGHT CALC] <> 0, ([H] * [W] * [L] * [WEIGHT CALC] / 1000000000), "-")

or:

Me.WEIGHT = IIf(Val([WEIGHT CALC] & "")<> 0, ([H] * [W] * [L] * [WEIGHT CALC] / 1000000000), "-")
 
Last edited:

Mile-O

Back once again...
Local time
Today, 06:12
Joined
Dec 10, 2002
Messages
11,316
How do I get the data in a form control to populate the corresponding table field when the control source box already contains an expression for making calculations within the form?

ALARM BELL!

Do not do this. If you are calculating it at run-time, you always calculate it at run-time. This is part and parcel of database design in that you do not store calculated values. (See: normalisation.)

Quick reason why: If you have a field called Quantity and a record's value is 2 and you have another field called Price and it's value is $2, then you do not have a third field called, say, Total Price, which stores the value of $4. Instead, you just multiply $2 by 2 every time you need to use it. If you stored the value, and then someone comes along and changes the quantity to 3, then you are still recording $4, when it should now be $6.

Take that simple example, and apply it to your predicament. You have all the values you need to calculate the end result. Just calculate it each time.
 

missinglinq

AWF VIP
Local time
Today, 02:12
Joined
Jun 20, 2003
Messages
6,423
What Mile-O said! Rarely does a situation arise where it is appropriate to store a calculated value...and this is not one of those situations!

Linq ;0)>
 

Users who are viewing this thread

Top Bottom