vba 如何在 excel 用户表单文本框中检查空值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7475023/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 11:53:55  来源:igfitidea点击:

How do I check for null value in an excel userform textbox?

vba

提问by user793468

Why does the following not work?

为什么以下不起作用?

If IsNull(Me.TextBox1.Value) = True Then

MsgBox "Null"

Else

MsgBox "Not Null"

End If

Here, I don't enter any value in "TextBox1" but it still passes the first ifloop and displays "Not Null"

在这里,我没有在“TextBox1”中输入任何值,但它仍然通过第一个if循环并显示“Not Null”

How do I check for null values?

如何检查空值?

回答by Bruno Leite

Try

尝试

If me.textbox1= vbNullString then

[]'s

[] 的

回答by HRgiger

I don't have Excel on my computer, but can you try Me.TextBox1.Textinstead of Me.TextBox1.Value.

我的电脑上没有 Excel,但你可以试试Me.TextBox1.TextMe.TextBox1.Value.

回答by Suryadi

I think, the default value of blank textbox is ""

我认为,空白文本框的默认值是 ""

Try:

尝试:

If (Me.TextBox1.Value) = "" Then 
   MsgBox "Null" 
Else 
  MsgBox "Not Null"  
End If  

Lets see if it is working

让我们看看它是否有效