简体   繁体   English

MS-Access 2010:无需选择/突出显示字段内容即可设置焦点

[英]MS-Access 2010: setting focus without selecting / highlighting field contents

What I'm looking for is deselecting / dehighlighting a field's contents by using vba , just as if the user would click with the mouse in that field. 我正在寻找的是使用vba取消选择/突出显示字段的内容 ,就像用户在该字段中用鼠标单击一样。 Maybe the solution is too easy to have found its way to forums ? 也许解决方案太容易找到论坛的方法了? Simple goal, but it seems difficult to be achieved. 简单的目标,但似乎很难实现。 SendKeys always got errors. SendKeys总是出错。 The .OnClick property does not simulate a click, just tells what to do on click. .OnClick属性不会模拟点击,而只是告诉您如何进行点击。

My form (main- with subform) has many fields between which the focus is moved depending on the fields values. 我的窗体(主窗体和子窗体)具有许多字段,焦点之间的移动取决于字段的值。 For this I'm using xyz**.SetFocus** Works fine so far, but in many fields the user should be able to immediately edit the contents by keyboard, without first clicking into that field with the mouse. 为此,我目前使用xyz **。SetFocus **可以正常工作,但是在许多字段中,用户应该能够立即通过键盘编辑内容,而无需先用鼠标单击该字段。 The keyboard arrows should move the cursor, not highlight the next or previous field. 键盘箭头应移动光标,而不突出显示下一个或上一个字段。 Combobox fields should not be highlighted at all. 组合框字段完全不应突出显示。

There is a database option (File/Options/Client Settings/) which should enable this by selecting "Go to start of field" or "Go to end of field". 有一个数据库选项(文件/选项/客户端设置/),应通过选择“转到字段开始”或“转到字段结束”来启用此选项。 However, this does not work on combobox fields (optically bad). 但是,这不适用于组合框字段(可能是错误的)。 Moreover, this option should not be set for the whole database but depend on which form has focus, and even better on the field getting focus and its contents. 此外,不应为整个数据库设置此选项,而应取决于具有焦点的表单,甚至取决于获得焦点及其内容的领域。

You can use the .SelStart and .SelLength properties. 您可以使用.SelStart.SelLength属性。

With Me.myCombobox
    .SetFocus
    .SelStart = 0
    .SelLength = 0           ' Nothing selected
End With

With Me.myCombobox
    .SetFocus
    .SelLength = Len(.Text)  ' Content selected
End With

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM