469,266 Members | 1,679 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,266 developers. It's quick & easy.

Which form event fires after any field is updated?

91
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_AfterUpdate, Form_DataChange but no luck
Jul 23 '10 #1
8 20206
NeoPa
32,171 Expert Mod 16PB
Strangely, the Help system seems to know nothing of the Form_AfterUpdate 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.
Jul 23 '10 #2
Stewart Ross
2,545 Expert Mod 2GB
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
Jul 24 '10 #3
missinglinq
3,532 Expert 2GB
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)>
Jul 24 '10 #4
OldBirdman
675 512MB
I think the answers given miss the original question.

There are 20 textboxes, txt01, txt02, ... txt20. Assume each has the value of 1. Therefore
Expand|Select|Wrap|Line Numbers
  1. 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.
Jul 24 '10 #5
OldBirdman
675 512MB
I missed the suggestion by NeoPa that is the same as my solution, an event on each of the textboxes. Sorry NeoPa.
Jul 24 '10 #6
NeoPa
32,171 Expert Mod 16PB
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
Jul 24 '10 #7
OldBirdman
675 512MB
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.
Jul 24 '10 #8
FishVal
2,653 Expert 2GB
Just my 5c

Regards,
Fish
Jul 24 '10 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

19 posts views Thread by Heidi Hundåla | last post: by
5 posts views Thread by Mike Salter | last post: by
3 posts views Thread by Drex10 | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.