vba 如何测试特定控件是否具有焦点?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20373426/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:20:27  来源:igfitidea点击:

how to test if a particular control has focus?

vbams-accessms-access-2007access-vba

提问by user1921704

i have access 2007 form and i want to test if a particular control (toggle button) has the focus ,

我可以访问 2007 表单,我想测试特定控件(切换按钮)是否具有焦点,

something like :

就像是 :

if gotfocus(mytoggle) then
dosomething
endif

or maybe like :

或者可能喜欢:

if me.mytoggle.setfocus = true then
dosomething
endif

I have searched and cannot find this , can someone tell me what is correct top to do this ?

我已经搜索过但找不到这个,有人能告诉我什么是正确的吗?

回答by jacouh

This for the current form:

这对于当前的形式:

If (mytoggle Is Me.ActiveControl) Then

This for the current Access.Application:

这对于当前的 Access.Application:

If (mytoggle Is Screen.ActiveControl) Then

Be careful, if no control has focus, *.ActiveControl may not exist.

请注意,如果没有控件具有焦点,*.ActiveControl 可能不存在。