2007 subform events firing
-
Tuesday, June 15, 2010 1:14 AM
I have vba in the OnExit event of a text box in a subform - but it is definitely firing before one exits the text box - - - - haven't totally isolated but seems to be firing on focus of the subform.....
Anyone out there know about this?
All Replies
-
Tuesday, June 15, 2010 5:00 AM
I normally use the After update event. Might try moving your code there.- Marked As Answer by Tim LiModerator Friday, June 18, 2010 10:06 AM
-
Tuesday, June 15, 2010 6:09 AM
The OnExit event fires when the focus leaves the control. It may also fire when the record is saved (e.g. if it is the last one in the tab order.)
When the focus moves into or out of a subform, the OnExit event of the active control fires.
What are you using the Exit event for? For validation, it's more common to use the Before- or AfterUpdate event of the control, or (for record level validation or comparison of controls) the BeforeUpdate event of the form.
Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users - http://allenbrowne.com/tips.html Reply to forum, rather than allenbrowne at mvps dot org.- Marked As Answer by Tim LiModerator Friday, June 18, 2010 10:06 AM
-
Tuesday, June 15, 2010 2:19 PM
thanks for the sanity check + info. Definitely it is firing alot and so I wanted to be sure if that was normal or if a fix/patch was involved.
it is not intuitively obvious that controls that have an OnExit event would all fire when focus moves in/out of the subform in general....and hard to find a textbook that gets to that level of advice....
the reason to use the OnExit event (if it truly fired only on user tabbing exit) is trivial but rational......I know the user is definitely going to be tabbing across the whole record but I don't know into which field they might put data; so the rational part was to put it once at the OnExit event of the first field of the tab sequence rather than repeat identical code at each field plus with an If/Then to be sure it doesn't get fired multiple times.... but hey, it isn't (wasn't ) that big of deal to modify to the AfterUpdate. Works ok now.
Mainly I was trying to get a handle on whether the behavior was normal or not......will presume that all controls' OnEnter event might also fire in a subform's general focus...
Thanks.
-
Tuesday, June 15, 2010 11:41 PM
Okay. Sounds like you're fine now.
If you are merely tracking when the user visited a record, Form_Current might help. If you are tracking when an edit begins, Form_Dirty might work. If you want to know when the user starts entering a new record, Form_BeforeInsert works well.
HTH
Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users - http://allenbrowne.com/tips.html Reply to forum, rather than allenbrowne at mvps dot org.

