|
当你的选项卡从一个文本框或备注字段到另一个形式,突出显示文本控制。这很容易让用户通过按一个键而不小心删除文本。通过几行代码,您可以将插入点放到文本框中第一的位置上,把意外删除文本的风险减小到最小化。
为此,给文本框的GotFocus事件创建一个程序。在GotFocus事件过程中,设置文本框的SelLength属性。 下面的例子说明了如何为一个取名为txtFirstName的文本框做这个功能。
VBA代码如下:
Private Sub txtFirstName_GotFocus()
Me.txtFirstName.SelLength = Me.txtFirstName.SelStart
End Sub
原文:How to: Prevent the Accidental Erasure of Data When Moving Between Controls on a Form
When you tab from one text box or memo field to another in a form, the text in the control is highlighted. This makes it easy for users to accidentally delete the text by pressing a key. By using a few lines of code, you can move the insertion point to the first position in the text box, minimizing the risk of accidentally deleting the text.
To do this, create a procedure for the text box's GotFocus event. In the GotFocus event procedure, set the SelLength property of the text box to its SelStart property. The following example illustrates how to do this for a text box named txtFirstName.
VBA:
Private Sub txtFirstName_GotFocus()
Me.txtFirstName.SelLength = Me.txtFirstName.SelStart
End Sub
|
|