为什么我的.SETFOCUS忽略? [英] Why is my .setfocus ignored?

查看:167
本文介绍了为什么我的.SETFOCUS忽略?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在那是为了允许重复输入一个号码,按下回车键,并让脚本做的东西一个文本框的访问形式。对于速度,现场应保持关注的焦点后, 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆