将ActiveX文本框设置为空值后,先前的文本会短暂出现在框中,然后再次消失 [英] After setting ActiveX textbox to empty value, previous text briefly appears in box before disappearing again

查看:192
本文介绍了将ActiveX文本框设置为空值后,先前的文本会短暂出现在框中,然后再次消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ActiveX TextBoxes在电子表格上创建了​​数据输入表单。这些与提交详细信息按钮和清除数据按钮结合在一起。执行结束时,两个按钮都将文本框重新设置为空白,以供下一个用户填充。

I created a data entry form on a spreadsheet using ActiveX TextBoxes. These are coupled with a submit details button and a clear data button. Both buttons at the end of execution set the text boxes back to blank to be refilled by the next user.

在将框设置为之后,当用户开始每次用户选择一个文本框时都填写表格,以前的输入详细信息会短暂出现在文本框中,然后消失。

After the boxes are set to "", when the user begins filling the form each time the user selects one of the text boxes the previous entry details briefly appear in the text box then disappear.

这是一个相当令人沮丧的问题,因为我

This is a quite frustrating issue as I am trying to make it so the previous users details are hidden.

我搜索了很多关于将文本框设置为空的最佳方法的文章,看来主要的方法是将.text属性设置为。

I searched many articles on the best way to set text boxes to empty and it seems that the main way is to set the .text property to "". There seems to be no mention of this behavior.

Sub clearForm()
'    Worksheets("Student Data").userName.Text = ""
'    Worksheets("Student Data").emailAddr.Text = ""
'    Worksheets("Student Data").contactNum.Text = ""
'    Worksheets("Student Data").Course.Text = ""
'    Worksheets("Student Data").gradDate.Text = ""
'    Worksheets("Student Data").addComment.Text = ""

    textbox1clear
End Sub

Sub submitData()
    'Code here that takes users entered data and outputs to hidden and protected sheet    

    'After data copied text boxes are cleared of users information, same as above sub
    Worksheets("Student Data").userName.Text = ""
    Worksheets("Student Data").emailAddr.Text = ""
    Worksheets("Student Data").contactNum.Text = ""
    Worksheets("Student Data").Course.Text = ""
    Worksheets("Student Data").gradDate.Text = ""
    Worksheets("Student Data").addComment.Text = ""
End Sub

Sub textbox1clear()
    Dim sel
    sel = Selection.Address
    Sheet1.userName.Activate
    Application.SendKeys ("Test ")
    Sheet1.userName.Value = ""
    Range(sel).Activate
End Sub

预期-文本框中应清除可供下一个用户使用的数据。

Expected - Text boxes should be clear of data ready for next user.

实际-文本框是透明的,直到用户选择它们以开始输入数据为止,此时先前的输入内容短暂出现在框中,然后再次消失。

Actual - Text boxes are clear until user selects them to begin entering data at which point previous entry briefly appears in the box and disappears again.

推荐答案

这是常见的文本框行为。除非再次选择该文本框,否则更改实际上不会完成。我可以看到,如果其他用户使用它并且输入的数据是机密信息,这将带来不便。经过大量测试后,我发现的唯一可行的方法是清除VBA,然后选择并取消选择输入框,并使用sendkey模拟新的用户输入,从而触发此闪烁。

This is common textbox behaviour. Unless the textbox is selected again, the changes aren't actually completed. I can see how this is inconvenient if used by other users and data entered is confidential. After numerous tests, the only working way I found around this is to trigger this flicker after clearing by making VBA select and deselect the input box, and simulating new user input with sendkeys.

Sub textbox1clear()
Dim sel
sel = Selection.Address
Sheet1.TextBox1.Activate
Application.Sendkeys(" ")
Sheet1.TextBox1.Value = ""
Range(sel).Activate
End Sub

我建立了一个选择调用,以使子菜单(通过按钮调用)更加(无缝)无缝。但是,如果忽略此选项,并且在运行此子项后未进行选择,则取消选中文本框时,文本将再次闪烁。

I have built in a selection recall to make it (slightly) more seamless if the sub is called with a button. However if this is omitted and no selection is made after this sub is ran, the text will flicker again when the textbox is deselected.

也请注意,应始终手动调用此选项,如果像我一样从 Textbox_LostFocus 调用它,只要未选择该文本框,它将进入一个连续循环。

Also note this should always be called manually, if it is called from a Textbox_LostFocus like I did, it will enter a continuous loop as long as the textbox isn't selected.

这不是一个非常优雅的解决方案,但是如果优先考虑数据保护,那么就可以解决问题。

It's not a very elegant solution, but if data protection is priority, it will do the trick.

如果这还不够,您可能想要到完全隐藏您的输入如果可以的话。

If this is not sufficient, you might want to hide your input altogether if this is an option.

这篇关于将ActiveX文本框设置为空值后,先前的文本会短暂出现在框中,然后再次消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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