Which form event fires after any field is updated?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • matt753
    New Member
    • May 2010
    • 91

    Which form event fires after any field is updated?

    I'm trying to find which event fires after any of the textboxes are updated on my form. I have an average field, and any time a user changes any one of the 20 textboxes I want it to update.

    Or, is there a better way to do this?



    I have tried Form_AfterUpdat e, Form_DataChange but no luck
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32657

    #2
    Strangely, the Help system seems to know nothing of the Form_AfterUpdat e event. Assuming you've tried that though, I can only assume it doesn't do what you require.

    In your shoes I'd put AfterUpdate event procedures on each of your 20 TextBoxes that simply call the procedure that sets up your average value.

    Comment

    • Stewart Ross
      Recognized Expert Moderator Specialist
      • Feb 2008
      • 2545

      #3
      Hi. The form's AfterUpdate event will only fire after you move away from the current edited record - by saving it, moving focus to another record or form, or by closing the form.

      As you need to update your computed field every time one of the contributing textboxes has been updated you will indeed need to use the AfterUpdate event of each textbox to call your requery method, as NeoPa has advised.

      For a full description of the form's afterupdate event, see this MSDN reference item.

      -Stewart

      Comment

      • missinglinq
        Recognized Expert Specialist
        • Nov 2006
        • 3533

        #4
        An alternate method would be to
        1. Create a Query based on your underlying Table
        2. Create a Calculated field in the Query, using your expression for calculating the average
        3. Base your Form or Report on the Query

        Generic code for the calculated field would be

        AverageField:([Field1] + [Field2] + [Field3])/[Field4]

        Note the square brackets around each field name.

        Then in your form or report use AverageField where the average is needed. It will be automatically re-calculated anytime any of the twenty fields are changed.

        Linq ;0)>

        Comment

        • OldBirdman
          Contributor
          • Mar 2007
          • 675

          #5
          I think the answers given miss the original question.

          There are 20 textboxes, txt01, txt02, ... txt20. Assume each has the value of 1. Therefore
          Code:
          txtAvg = (txt01 + txt02 + ... + txt20) / 20
          will assign a "1" into txtAvg. If txt14 is changed to 21, then txtAvg needs to be "2" as soon as txt14 is changed. Now if the user changes txt08 to 41, txtAvg needs to change to "4".
          So the question is: "Where is the above line of code best put so that whenever any of the textboxes txt01, txt02, ... is changed, txtAvg shows the correct value?"
          The form's On Dirty Event only fires once, after the first change. It does not fire on subsequent changes. There is no On Dirtier Event.
          I would probably put the above logic in a function, and then for the On Change or After Update event for each of the 20 textboxes call the function.
          The function could be called from the form's On Key Press function and be more dynamic, but this requires knowing which control has the focus (is being changed), and using .Text or .Value as necessary. This can get messy if the user makes a typo.

          Comment

          • OldBirdman
            Contributor
            • Mar 2007
            • 675

            #6
            I missed the suggestion by NeoPa that is the same as my solution, an event on each of the textboxes. Sorry NeoPa.

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32657

              #7
              There seems to be some confusion here OB.

              I haven't tested Linq's solution myself, but if it works it certainly seems as if it would fit the requirements perfectly, doing everything as you've explained it needs to do.

              This is also true of the suggestion in my post (as clarified somewhat by Stewart). In fact, your suggestion to use the AfterUpdate event procedure of each of the twenty TextBoxes to call the function that does the working out matches what I suggested in my post.

              Where you suggest options of using the Change event, or even the KeyPress event, I have to differ. These I feel would be quite inappropriate for this as the average value would change while the operator was typing in their value. A value of 4 should never be used to determine the average, yet this would occur in that scenario before they'd finished typing in 41.

              PS. Now I see post #6 :D
              Last edited by NeoPa; Jul 24 '10, 12:51 PM.

              Comment

              • OldBirdman
                Contributor
                • Mar 2007
                • 675

                #8
                My apologies to Linq as his solution does work. I have now tested it. And I learned something about how dynamic queries are after they have 'run'. Not sure I understand, though.
                As NeoPa's Post#2 suggestion is the same as mine, and as the original question clearly states "I'm trying to find which event fires after any of the textboxes are updated on my form.", I have nothing to add.

                Comment

                • FishVal
                  Recognized Expert Specialist
                  • Jun 2007
                  • 2656

                  #9
                  Just my 5c

                  Regards,
                  Fish

                  Comment

                  Working...