calculate values as they are entered

  • Thread starter Thread starter max
  • Start date Start date
M

max

I have a form that has a number of txtboxes bound to
integer fields. I want the total of the integers entered
to appear in another textbox immediately any integer is
typed in the txtboxes (even before the record is saved.)
How do I go about this and on what form event do I put the
respective procedure, macro, query,etc that does this?
 
All you need to do is put
=[Text0]+[Text2]+[Text4]...etc
in the Control Source of the unbound text box. (Use the actual names of
your textboxes, of course)

After you enter a value in a bound textbox, you only have to move to another
control to have the addition update.
 
For each integer control, in the After Update event, add:

Me.Recalc

which forces Access to recalculate all calculated controls.

HTH
Kevin Sprinkel
Becker & Frondorf
 
Try something along the following lines

1. Write a private procedure on the form's code page to
accumulate the values e.g

Private Sub Accumulate()
dim lngTotal as long

lngTotal = 0
if isnumeric (textbox1.value) then
lngTotal = textbox1.value
end if
if isnumeric (textbox2.value) then
lngTotal = lngTotal + textbox2.value
end if
<repeat for as many text boxes as you have>

textboxTotal.Value = lngTotal
End Sub

2. Then for each textbox, call this procedure from the
AfterUpdate method e.g.
Private Sub textbox1_AfetrUpdate()
Accumulate
End Sub

Hope That Helps

Gerlad Stanley MCSD
 
Back
Top