Why is my .setfocus ignored?
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...
- click on
access options
- select
Advanced
- select
Don't move
fromMove after enter
- click
ok
It will work 100%
A workaround is moving the focus to another control and then back to the first control. Like this:
Private Sub MyFld_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
DoStuff
Me.anotherControl.SetFocus
Me.MyFld.SetFocus
End If
End Sub