Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > Access数据库-模块/函数/VBA

【译文】如何防止在窗体上移动时意外清除数据

时 间:2013-07-30 09:10:20
作 者:周芳   ID:24526  城市:上海
摘 要:某个控件会整体选定(例如:1234AAA),导致不小心按个键就会全清掉,如果一获得焦点并放在首位(放在1的前面)就可避免这情况

正 文:

来自:微软  翻译:周芳

【译文】如何防止在窗体上移动时意外清除数据


       当你的选项卡从一个文本框或备注字段到另一个形式,突出显示文本控制。这很容易让用户通过按一个键而不小心删除文本。通过几行代码,您可以将插入点放到文本框中第一的位置上,把意外删除文本的风险减小到最小化。


      为此,给文本框的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



Access软件网QQ交流群 (群号:483923997)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助