Instant update of calculated Text Box in Form

Posted on 2004-11-24
Last Modified: 2010-05-18
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?
Question by:Krobar
    LVL 26

    Expert Comment

    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.
    LVL 2

    Expert Comment

    Another event that can do the trick is the OnChange. Use anyway for your calculation the Nvl function to avoid calculation problems.

    Author Comment

    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?
    LVL 26

    Expert Comment

    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.
    LVL 58

    Accepted Solution

    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

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
    Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
    Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now