将重点转向主要形式 [英] Returning Focus to Main Form

查看:55
本文介绍了将重点转向主要形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,这是一个愚蠢的事情,但我似乎无法让它发挥作用。我有一个带有子表单的

表单(在连续表单视图中)。主窗体上的一个组合框

在AfterUpdate事件中有代码,它向子窗体添加一条记录(基于组合框值的
)并重新查询子窗体控制。我希望

焦点在完成时返回到主窗体上的组合框,但是如果有的话,我将无法获得它。用户输入一个值并按Enter键(

制表符到下一个控件,即子窗体)。我试过了:


Me.SetFocus

Me.MyCombo.SetFocus


哪个没有''似乎工作。有什么想法吗?


谢谢,


Neil

解决方案

我认为你在这里遇到了一些失败。如果您拦截焦点移动,那么您的代码将如何让用户完全离开文本框?

不要让焦点转移到其他地方?如果你把代码放在文本框上以停止

焦点移动,那就会发生什么。


你可以使用Exit事件拦截焦点移动,但每当用户试图离开文本框时,就会发生



即使您陷阱确定是否按下了Enter键,并停止

焦点移动只有在按下该键时(换句话说,让用户移动

焦点如果他/她按Tab键或点击进入另一个控件),但是我想b / b
会认为你的用户会厌倦不得不记住那个

Enter键不能继续只为那个控件上的

表格。


我建议你想出一个不同的方法来实现你想要的

< br $>
-


Ken Snell

< MS ACCESS MVP>

" Neil Ginsberg" < nr*@nrgconsult.com>在消息中写道

news:4i ***************** @ newsread1.news.pas.earthl ink.net ...

好的,这是一个愚蠢的事情,但我似乎无法让这个工作。我有一个带子表单的
表单(在连续表单视图中)。主
表单上的组合框在AfterUpdate事件中包含代码,该事件将子记录添加到子表单中(基于组合框的值)并重新查询子表单控件。我希望焦点在完成后返回到主窗体上的组合框,
但是如果用户输入一个值并按Enter键,我就不能这样做br />(选项卡指向下一个控件,即子窗体)。我试过了:

Me.SetFocus
Me.MyCombo.SetFocus

这似乎无法奏效。有什么想法吗?

谢谢,

Neil



见下文。


" Ken Snell [MVP]" <克拉*********** @ ncoomcastt.renaetl>在消息中写道

新闻:%2 **************** @ TK2MSFTNGP15.phx.gbl ...

我认为你在这里为自己做好准备。如果您拦截焦点移动,那么您的
代码将如何让用户完全离开文本框
并且不要让焦点转移到其他地方?


如果你的意思是用户永远无法离开组合框,那就是我正在做的事情,那不是真的。只有在AfterUpdate事件中,我才想要将焦点移回组合框。因此,如果用户输入

值并按Enter键,结果是焦点返回到组合框中。

如果用户只是通过控件进行制表,按Enter或Tab键,

他们可以保持罚款。没有激活代码。

如果你在文本框上放置代码来停止焦点移动,那就是
会发生的事情。


再次,只是在AfterUpdate中。

你可以使用Exit事件来拦截焦点移动,但只要用户尝试,就会发生这种情况离开文本框。


不是我想要的。

即使您陷阱以确定是否按下了Enter键,并且只有在那时才停止
焦点移动键被按下(换句话说,如果他/她按Tab键或点击另一个控件,让用户移动焦点),但我认为你的用户会厌倦不得不记住
对于
表单上的那个控件,Enter键不会继续前进。


再一次,不要那样。 Just AfterUpdate。

我建议您考虑采用不同的方法来实现您想要的目标。


希望我的上述说明澄清了我在这里要做的事情。


Neil

- -

Ken Snell
< MS ACCESS MVP>

" Neil Ginsberg" < nr*@nrgconsult.com>在消息中写道
新闻:4i ***************** @ newsread1.news.pas.earthl ink.net ...

确定,这是一个愚蠢的事情,但我似乎无法让这个工作。我有一个带有子表单的表单(在连续表单视图中)。主
表单上的组合框在AfterUpdate事件中有代码,它将子记录添加到子窗体中(基于组合框的值)并重新查询子窗体控件。
我想要当它完成时,重点回到主窗体上的组合框,但如果用户输入一个值并按下
Enter键,我就不能这样做了。到下一个控件,即子窗体)。我试过了:

Me.SetFocus
Me.MyCombo.SetFocus

这似乎无法奏效。有什么想法吗?

谢谢,

Neil




OK 。在表单上放置一个隐藏的文本框 - 将其命名为txtNoGo。将其

DefaultValue设置为0.


在文本框的AfterUpdate事件中,使用以下代码:


Private Sub TextBoxName_AfterUpdate()

Me.txtNoGo = 1

End Sub

在文本框的Exit事件中,使用以下代码:


Private Sub TextBoxName_Exit(取消为整数)

如果Me.txtNoGo = 1那么

Me.txtNoGo = 0

取消=真

结束如果


这将使用隐藏文本框作为标志,知道您已更新

文本框的值,焦点不应该移动。


-


Ken Snell

< MS ACCESS MVP>

" Neil Ginsberg" < nr*@nrgconsult.com>在消息中写道

news:kd ***************** @ newsread3.news.pas.earthl ink.net ...

见下文。

Ken Snell [MVP]" <克拉*********** @ ncoomcastt.renaetl>在消息中写道
新闻:%2 **************** @ TK2MSFTNGP15.phx.gbl ...

我想你是在这里为自己设置一些失败。如果您拦截焦点移动,那么您的
代码将如何让用户完全离开文本框?并且不要让焦点转移到其他地方?



如果你的意思是用户将永远无法离开组合框
我在做什么,这不是真的。只有在AfterUpdate事件中,我才想将焦点移回组合框。因此,如果用户输入
值并按Enter键,则结果是焦点返回到组合
框中。如果用户只是通过控件进行选项卡,按Enter或
选项卡,他们可以保持正常。没有代码被激活。

如果你把代码放在文本框上以停止焦点移动,那就会发生什么。



您可以使用Exit事件来拦截焦点移动,但只要用户试图离开就会发生这种情况文本框。



不是我想要的。


即使您陷阱以确定是否按下了Enter键,并且只有按下该键才能停止
焦点移动(换句话说,如果他/她按Tab键或点击另一个控件,让用户移动焦点),但
我会认为你的用户会非常厌倦不得不记住
只有那个控件在表单上的Enter键不能继续前进。


<再一次,不要那样。 Just AfterUpdate。


我建议您考虑采用不同的方法来实现您想要的目标。


希望我的上述说明澄清了我在这里要做的事情。


-

< MS ACCESS MVP>

" Neil Ginsberg" < nr*@nrgconsult.com>在消息中写道
新闻:4i ***************** @ newsread1.news.pas.earthl ink.net ...

确定,这是一个愚蠢的事情,但我似乎无法让这个工作。我有一个带有子表单的表单(在连续表单视图中)。主
表单上的组合框在AfterUpdate事件中包含代码,该事件将记录添加到
子表单(基于组合框的值)并重新查询子表单
控件。我希望焦点在完成后返回到主窗体上的组合框
,但如果用户输入值
并按Enter键,我就无法做到这一点(哪个选项卡到下一个控件,这是
子窗体)。我试过了:

Me.SetFocus
Me.MyCombo.SetFocus

这似乎无法奏效。有什么想法吗?

谢谢,

Neil





OK, this is a stupid thing, but I can''t seem to get this to work. I have a
form with a subform (in continuous form view). A combo box on the main form
has code in the AfterUpdate event which adds a record to the subform (based
on the value of the combo box) and requeries the subform control. I want the
focus to return to the combo box on the main form when it''s done, but I
can''t get it to do so if the user enters a value and presses Enter (which
tabs to the next control, which is the subform). I''ve tried:

Me.SetFocus
Me.MyCombo.SetFocus

which doesn''t seem to work. Any ideas?

Thanks,

Neil

解决方案

I think you''re setting yourself up for some failure here. How will your code
let the user leave the textbox at all if you intercept a focus move and
don''t let the focus go elsewhere? If you put code on the textbox to stop the
focus move, that is what will happen.

You could use the Exit event to intercept the focus move, but that will
happen whenever the user tries to leave the textbox.

Even if you trap to determine if the Enter key was pressed, and stop the
focus move only if that key is pressed (in other words, let the user move
the focus if he/she presses Tab key or clicks into another control), but I
would think that your users will get very tired of having to remember that
the Enter key won''t work to move along for just that one control on the
form.

I suggest that you think of a different approach for what you want to
achieve.

--

Ken Snell
<MS ACCESS MVP>
"Neil Ginsberg" <nr*@nrgconsult.com> wrote in message
news:4i*****************@newsread1.news.pas.earthl ink.net...

OK, this is a stupid thing, but I can''t seem to get this to work. I have a
form with a subform (in continuous form view). A combo box on the main
form has code in the AfterUpdate event which adds a record to the subform
(based on the value of the combo box) and requeries the subform control. I
want the focus to return to the combo box on the main form when it''s done,
but I can''t get it to do so if the user enters a value and presses Enter
(which tabs to the next control, which is the subform). I''ve tried:

Me.SetFocus
Me.MyCombo.SetFocus

which doesn''t seem to work. Any ideas?

Thanks,

Neil



See below.

"Ken Snell [MVP]" <kt***********@ncoomcastt.renaetl> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...

I think you''re setting yourself up for some failure here. How will your
code let the user leave the textbox at all if you intercept a focus move
and don''t let the focus go elsewhere?
If you mean that the user will never be able to leave the combo box with
what I''m doing, that''s not true. It''s only in the AfterUpdate event that I
want to move the focus back to the combo box. Thus, if the user enters a
value and hits Enter, the result is that the focus is back in the combo box.
If the user is just tabbing through the controls, pressing Enter or Tab,
they can leave it fine. No code is activated.
If you put code on the textbox to stop the focus move, that is what will
happen.
Again, just in AfterUpdate.

You could use the Exit event to intercept the focus move, but that will
happen whenever the user tries to leave the textbox.
Not what I want.

Even if you trap to determine if the Enter key was pressed, and stop the
focus move only if that key is pressed (in other words, let the user move
the focus if he/she presses Tab key or clicks into another control), but I
would think that your users will get very tired of having to remember that
the Enter key won''t work to move along for just that one control on the
form.
Again, don''t want that. Just AfterUpdate.

I suggest that you think of a different approach for what you want to
achieve.
Hopefully my above notes have clarified what I''m trying to do here.

Neil

--

Ken Snell
<MS ACCESS MVP>
"Neil Ginsberg" <nr*@nrgconsult.com> wrote in message
news:4i*****************@newsread1.news.pas.earthl ink.net...

OK, this is a stupid thing, but I can''t seem to get this to work. I have
a form with a subform (in continuous form view). A combo box on the main
form has code in the AfterUpdate event which adds a record to the subform
(based on the value of the combo box) and requeries the subform control.
I want the focus to return to the combo box on the main form when it''s
done, but I can''t get it to do so if the user enters a value and presses
Enter (which tabs to the next control, which is the subform). I''ve tried:

Me.SetFocus
Me.MyCombo.SetFocus

which doesn''t seem to work. Any ideas?

Thanks,

Neil




OK. Put a hidden textbox on the form -- name it txtNoGo. Set its
DefaultValue to 0.

In your textbox''s AfterUpdate event, use this code:

Private Sub TextBoxName_AfterUpdate()
Me.txtNoGo = 1
End Sub
In the textbox''s Exit event, use this code:

Private Sub TextBoxName_Exit(Cancel As Integer)
If Me.txtNoGo = 1 Then
Me.txtNoGo = 0
Cancel = True
End If

This will use a hidden textbox as a flag to know that you''ve updated the
textbox''s value and that the focus should not move.

--

Ken Snell
<MS ACCESS MVP>
"Neil Ginsberg" <nr*@nrgconsult.com> wrote in message
news:kd*****************@newsread3.news.pas.earthl ink.net...

See below.

"Ken Snell [MVP]" <kt***********@ncoomcastt.renaetl> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...

I think you''re setting yourself up for some failure here. How will your
code let the user leave the textbox at all if you intercept a focus move
and don''t let the focus go elsewhere?



If you mean that the user will never be able to leave the combo box with
what I''m doing, that''s not true. It''s only in the AfterUpdate event that I
want to move the focus back to the combo box. Thus, if the user enters a
value and hits Enter, the result is that the focus is back in the combo
box. If the user is just tabbing through the controls, pressing Enter or
Tab, they can leave it fine. No code is activated.

If you put code on the textbox to stop the focus move, that is what will
happen.



Again, just in AfterUpdate.


You could use the Exit event to intercept the focus move, but that will
happen whenever the user tries to leave the textbox.



Not what I want.


Even if you trap to determine if the Enter key was pressed, and stop the
focus move only if that key is pressed (in other words, let the user move
the focus if he/she presses Tab key or clicks into another control), but
I would think that your users will get very tired of having to remember
that the Enter key won''t work to move along for just that one control on
the form.



Again, don''t want that. Just AfterUpdate.


I suggest that you think of a different approach for what you want to
achieve.



Hopefully my above notes have clarified what I''m trying to do here.

Neil


--

Ken Snell
<MS ACCESS MVP>
"Neil Ginsberg" <nr*@nrgconsult.com> wrote in message
news:4i*****************@newsread1.news.pas.earthl ink.net...

OK, this is a stupid thing, but I can''t seem to get this to work. I have
a form with a subform (in continuous form view). A combo box on the main
form has code in the AfterUpdate event which adds a record to the
subform (based on the value of the combo box) and requeries the subform
control. I want the focus to return to the combo box on the main form
when it''s done, but I can''t get it to do so if the user enters a value
and presses Enter (which tabs to the next control, which is the
subform). I''ve tried:

Me.SetFocus
Me.MyCombo.SetFocus

which doesn''t seem to work. Any ideas?

Thanks,

Neil





这篇关于将重点转向主要形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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