为什么我的.SETFOCUS忽略? [英] Why is my .setfocus ignored?
问题描述
我在那是为了允许重复输入一个号码,按下回车键,并让脚本做的东西一个文本框的访问形式。对于速度,现场应保持关注的焦点后, DoStuff()
完成的。
不过,虽然我敢肯定, DoStuff()
运行,焦点总是转到下一个字段的Tab键顺序。这就像 Me.MyFld.SetFocus
被忽略。
我如何保持专注于这个领域后, DoStuff()
做?
私人小组MyFld_KeyDown(主要code为整数,按住Shift键为整数)
如果key code = vbKeyReturn然后
DoStuff
Me.MyFld.SetFocus
结束如果
结束小组
如果你看一下<一href="http://office.microsoft.com/en-us/access-help/order-of-events-for-database-objects-HP005186761.aspx">the为了一键preSS将改变焦点事件,你可以看到,它总是遵循以下模式:
的KeyDown→更新前→更新后→出口→引发LostFocus
在那里
您可以重新设置聚焦的任何地方,它仍然会继续遵循的模式。因此,我们需要告诉它停止跟随的格局。更换你的 Me.MyFld.SetFocus
与 DoCmd.CancelEvent
,它应该解决您的问题。基本上,这只是踢你出上面的图案,因此退出
和引发LostFocus
事件永远不会触发...
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 the focus after DoStuff()
is done.
However, while I'm sure that DoStuff()
is run, the focus always goes to the next field in the tab order. It's like Me.MyFld.SetFocus
is being ignored.
How do I keep the focus on this field after DoStuff()
is done?
Private Sub MyFld_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
DoStuff
Me.MyFld.SetFocus
End If
End Sub
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...
这篇关于为什么我的.SETFOCUS忽略?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!