vba 在文本框中输入后如何导致 AfterUpdate 事件运行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24544875/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
After input in text box how do cause AfterUpdate event to run?
提问by Shari W
I have an Excel VBA userform with several text boxes.
The user will input a weight in a text box. They can then do other things on the form or click Apply, Update, Previous Event, Next Event or Cancel.
我有一个带有多个文本框的 Excel VBA 用户表单。
用户将在文本框中输入权重。然后他们可以在表单上执行其他操作或单击应用、更新、上一个事件、下一个事件或取消。
After the weight is input, it must be validated, and if it is OK, the form is marked as mbFormChanged=True
. This validation occurs in the text box's AfterUpdate event.
输入权重后,必须进行验证,如果OK,则将表单标记为mbFormChanged=True
。此验证发生在文本框的 AfterUpdate 事件中。
My problem is that if the user types in a value and immediately clicks Apply, Update, Previous Event or Next Event, the field is not validated and it is as if it was never changed.
我的问题是,如果用户输入一个值并立即单击“应用”、“更新”、“上一个事件”或“下一个事件”,则该字段未经过验证,就好像从未更改过一样。
I.e enter weight: 200[Update]
即输入重量:200[更新]
However, if the user tabs to another field after typing the weight, then it is validated and the form is marked as changed.
但是,如果用户在输入权重后切换到另一个字段,则会对其进行验证并将表单标记为已更改。
I.e. enter weight: 200[Tab][Update]
即输入重量:200[Tab][更新]
How can I make sure AfterUpdate runs when a command button is clicked immediately thereafter?
在此后立即单击命令按钮时,如何确保 AfterUpdate 运行?
I can't put the validation at the point of OK/Apply because the moment a user enters a new weight and it is valid, it immediately updates many other fields and lists visible on the form (real time update).
我不能在 OK/Apply 点进行验证,因为当用户输入新的权重并且它有效时,它会立即更新表单上可见的许多其他字段和列表(实时更新)。
回答by Brad
I assume this is an Excel user form in which case I don't think there is a built in AfterUpdate
event. Excel forms are not bound to anything (unlike Access) so there is nothing the formupdates. You'll need to make your own AfterUpdate
event.
我认为这是一个 Excel 用户表单,在这种情况下,我认为没有内置AfterUpdate
事件。Excel 表单没有绑定到任何东西(与 Access 不同),因此表单没有任何更新。您需要制作自己的AfterUpdate
活动。
回答by L42
As commented, you can try this:
正如评论的那样,你可以试试这个:
Private Sub TextBox1_Change()
If (MsgBox("Done?", vbYesNo)) = vbYes Then Me.TextBox2.SetFocus 'Or any other ctrl
End Sub
Above code like forces TextBox1_AfterUpdate()event.
上面的代码类似于强制TextBox1_AfterUpdate()事件。