calculate values as they are entered

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?
 
R

Roger Carlson

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.
 
K

Kevin Sprinkel

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
 
G

Gerald Stanley

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
 
K

Kevin Sprinkel

My apologies, max. Roger is absolutely correct; there's
no need for any code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top