有没有办法像在Excel中那样清除按键上的文本框。
我尝试了以下代码,但它在单击文本框时清除了文本。 我希望它在按下某个键时清除它。
Private Sub Text10_GotFocus() Text10.Value = "" End SubIs there any way to clear the textbox on keypress like in excel.
I tried the following code but it clears the text when clicking on the textbox. I want it to clear it when a certain key is pressed.
Private Sub Text10_GotFocus() Text10.Value = "" End Sub最满意答案
只要该控件获得焦点,您就可以选择控件的整个文本内容。 然后您的按键将替换所选文本。
如果希望每个表单上的每个文本框都出现这种情况,可以将“行为输入字段”设置为“选择整个字段”。 (在Access 2007中,从Office按钮 - >访问选项 - >高级查找该设置,然后查看该对话框的编辑标题下。对于Access 2003,请参阅此页 。)
该设置不仅应用于表单控件,还应用于数据表视图中的表和查询。 如果这不是您想要的,您可以在表单的模块中使用VBA来选择仅特定控件的文本:
Private Sub MyTextBox_GotFocus() Me.MyTextBox.SelStart = 0 Me.MyTextBox.SelLength = Len(Me.MyTextBox) End Sub如果要对多个控件执行此操作,可以创建一般过程:
Private Sub SelectWholeField() Me.ActiveControl.SelStart = 0 Me.ActiveControl.SelLength = Len(Me.ActiveControl) End Sub然后从单个控件的焦点事件中调用该过程,如下所示:
Private Sub MyTextBox_GotFocus() SelectWholeField End SubYou could select the control's entire text content whenever that control gets focus. Then your keypress would replace the selected text.
If you want that to happen for every text box on every form, you can set "Behavior entering field" setting to "Select entire field". (In Access 2007, find that setting from Office Button -> Access Options -> Advanced, then look under the Editing heading of that dialog. For Access 2003, see this page.)
Not only will that setting be applied to form controls, but also to tables and queries in datasheet view. If that's not what you want, you can use VBA in your form's module to select the text for only specific controls:
Private Sub MyTextBox_GotFocus() Me.MyTextBox.SelStart = 0 Me.MyTextBox.SelLength = Len(Me.MyTextBox) End SubIf you want to do that for multiple controls, you could create a general procedure:
Private Sub SelectWholeField() Me.ActiveControl.SelStart = 0 Me.ActiveControl.SelLength = Len(Me.ActiveControl) End SubThen call that procedure from the got focus event of an individual control like this:
Private Sub MyTextBox_GotFocus() SelectWholeField End Sub更多推荐
清除,Sub,textbox,clear,电脑培训,计算机培训,IT培训"/> <meta name="descript
发布评论