Field update problem from VB

  • Thread starter Thread starter Henry
  • Start date Start date
H

Henry

Hi

Is there any good ideas how to update form vb code always
after some values are changed / added by vb (not user).

I have some code behind subforms vb and there are
calculations behind "Form_Current" section those I need to
re-calculate after some values are changed or added.

The problem is that if list box value is calculated in vb,
access wont regognize that valua has changed.

Simple example:
There are 4 "list box" objects in the form.
- user_input_box_01
- user_input_box_02
- vb_calculated_box_01
- sum_of_user_input_and_vb_calculated_01

**This code is behind every 4 objects**
Private Sub <some_of_those_4_objects>_AfterUpdate()
Form_Current
End Sub

**This code is behind form_current**
Dim var_user_input_box_01, var_user_input_box_02
var_user_input_box_01 = Me.user_input_box_01.Value
var_user_input_box_02 = Me.user_input_box_02.Value

Me.vb_calculated_box_01.Value = var_user_input_box_01 +
var_user_input_box_02

Dim var_vb_calculated_box_01
var_vb_calculated_box_01 = me.vb_calculated_box_01
me.sum_of_user_input_and_vb_calculated_01.value =
var_user_input_box_01 + var_vb_calculated_box_01

**End of code behind form_current**

How it works:
User gives values in "user_input_box_01"
and "user_input_box_02"
After "user_input_box_02" value is
entered "vb_calculated_box_01" value is calculated
correctly,
but.... "sum_of_user_input_and_vb_calculated_01" is empty.

When I click to "vb_calculated_box_01"
or "sum_of_user_input_and_vb_calculated_01" box -
"sum_of_user_input_and_vb_calculated_01" value is
calculated correctly.

Also if I change user values, "vb_calculated_box_01" value
is calculated correctly,
but.... "sum_of_user_input_and_vb_calculated_01" is
calculated by previous user values until I
click "vb_calculated_box_01"
or "sum_of_user_input_and_vb_calculated_01"..

How it should works:
Some code or etc. function that I don´t need always to
click those boxes would be very nice =)

Regards from Finland,
Henry
 
Try Me.Refresh after the calculation is performed. It may
be more efficient to set the COntrol Source of the field
to your calculation = var_user_input_box_01 +
var_user_input_box_02. Then in the afterupdate event for
each field affecting this calculation, have Me.Refresh.
This will refresh the current form and should display your
caluclated value.

Also, these fields should be unbound. I would not, under
normal circumstances, be storing a calculated value. You
can always recalculate the value when you neeed it. The
only reason I can think of off hand to store a calculated
value is if you need to know what a value was at the time
it was calculated. I am sure there are others, but under
most circumstances, display the value, don't store it.

Hope that helps!

Kevin
 
Back
Top