When to use 'after update' and when to use OnChange events ??

K

Kizzwozz

Can anyone provide guidance please on when you would use 'onchange' (eg: to
set a date based on entry into a field) as opposed to 'after update'.
Thanks
 
A

Allen Browne

The Change event happens with each keystroke. Therefore it is quite unusual
to work with this event.

Using your date example, the Text in the control might be just:
8
the first type the Change event fires, and then:
8/
the second time it fires. Clearly, there's no sense trying to respond to a
date, because there's no valid date there yet.

Therefore you use AfterUpdate to respond to the new Value, and Change only
when you want to respond to each keystroke.
 
R

Rick Brandt

Kizzwozz said:
Can anyone provide guidance please on when you would use 'onchange'
(eg: to set a date based on entry into a field) as opposed to 'after
update'. Thanks

The Change event fires with every keystroke and therefore is used relatively
rarely. AfterUpdate is when you are finished changing the control, usually
when you tab out of it, though that is not necessary with ComboBoxes or
ListBoxes.
 
K

Kizzwozz

Thanks Allen and Rick - appreciate your assistance. Just as a matter of
interest, can you suggest a situation where you would want to use OnChange ?
I presume MS had some situations in mind when they provided it as an event
option.
ta
 
D

Douglas J. Steele

A common use of the OnChange event would be to filter what's displayed in a
form.

When the user types S in the text box, the form displays only those names
starting with S. When the user types M (so that SM is now in the text box),
the form displays only those names starting with SM. And so on.
 
J

John Spencer

You might use the Change Event when you want to
-- suppress certain characters from being entered
-- change the source of a combobox based on what is entered so far
-- limit the length of a string being input
-- change the case of characters entered as the data is being typed
-- update an associated listbox as you enter information into a textbox

It is entirely possible to wait to do much of that in the After Update event.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 
Top