Why is my .setfocus ignored?

前端 未结 6 2108
一生所求
一生所求 2020-12-06 11:46

I have an Access form with a textbox that is meant to allow for repeatedly typing a number, hitting enter, and letting a script do stuff. For speed, the field should keep t

6条回答
  •  心在旅途
    2020-12-06 12:30

    If you look at the order of events for a keypress that would change focus, you can see that it always follows this pattern:

    KeyDown → BeforeUpdate → AfterUpdate → Exit → LostFocus
    

    You can re-set the focus anywhere in there and it will still keep following the pattern. So we need to tell it to stop following the pattern. Replace your Me.MyFld.SetFocus with DoCmd.CancelEvent and it should fix your problem. Basically, this just kicks you out of the above pattern, so the Exit and LostFocus events never fire...

提交回复
热议问题