Instant update of calculated Text Box in Form

I have a form which contains a Text Box which calculates a value from a user input text box on the same form.

The trouble is it only does this once the user has stopped typing and clicks somewhere else. I assume I have to put some sort of expression into the correct event property of the user input text box but dont know an expression to force uppdate of another text box. Does anyone know?
KrobarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dannywarehamCommented:
Other controls will update when the focus changes from control to control.

It is possible to do an update through code, by placing it on the OnKeyDown event.
However, if you're using calculated fields, this will cause errors that will have to be managed too.
0
AngelinoMCommented:
Another event that can do the trick is the OnChange. Use anyway for your calculation the Nvl function to avoid calculation problems.
0
KrobarAuthor Commented:
This seems alot more difficult than I thought it would be (I upped the points too). I tried entering simple piece of code but it does not execute when I expect.

For example if you have two text boxes called Text1 & Text2 and I wanted to update Text2 (which has no control source) using the following "Text2.Value = Text1.Value * 5" every time a key is pressed in Text1, how is this done?
0
dannywarehamCommented:
I can't find a way to do it whilst you still have focus on text1.

Having the focus on the control that is part of a calculated field stops the events from firing - so you can't use the Timer event on the form either.
0
harfangCommented:
The problem here is that the text box has two or three properties describing the content.
  .Value is changed once the entry in the box has been validated (and converted sometimes)
  .Text is only available while the control has the focus

To update Text2 with Text1 on the fly, use:

Private Sub Text1_AfterUpdate()
    Me.Text2.Value = Text1.Value * 2
End Sub

Private Sub Text1_Change()
    Me.Text2.Value = Val(Text1.Text) * 2
End Sub

If Text1 is formatted as short time, you will see this:

1   -->   2
12   -->   24
12:30   -->   24
(leave)   -->   1.0416666   (= 25/24 or 1 day and 1 hour)

You see that the information is quite different. Text is a String property, Value will depend on the formatting and/or on the underelying field (string, number, date/time, etc.)

Good Luck
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.