2017-04-06 114 views
0

我正在使用简单的IF语句,但由于某些原因,单击命令按钮时它们会被忽略。简单的IF语句不起作用

我错过了什么?

If Text4 = "" Then 
MsgBox "You must add a GS Reference", vbInformation 
Exit Sub 
Else 
End If 

If Text6 = "" Then 
MsgBox "You must add a Service Account number", vbInformation 
Exit Sub 
Else 
End If 

If Text8 = "" Then 
MsgBox "You must pick an advisor", vbInformation 
Exit Sub 
Else 
End If 

If Me.Text10 = "" Then 
MsgBox "You must select a date received option", vbInformation 
Exit Sub 
Else 
End If 

If Me.Text12 = "" Then 
MsgBox "You must select a date failed option", vbInformation 
Exit Sub 
Else 
End If 

对我来说,这些应该只是检查如果一个文本框是空白的,如果空白显示一条消息停止运行代码。但它根本不工作。

+2

当然,你已经用破发点已经调试代码和单步执行?如果没有,请这样做。如果您已经这样做了,请将相关信息添加到您的问题中。 – Heinzi

+1

除了@Heinzi,记住null不是零长度的字符串。 – Fionnuala

+0

@Fionnuala是对的。使用:如果IsNull(Me!Text10.Value)Then'。 – Gustav

回答

4

尝试这样的替代检查文本框的命令:

If Nz(Text6,"") = "" Then 

If Len(Nz(Text6,"") = 0 Then 

最后一个工作快一点点

+0

我倾向于使用&,但无论适合什么, – Fionnuala

+0

另一方面,OP应该使用正确的控制名称,否则它会回来并咬人。 – Fionnuala

+0

谢谢 - 这工作。你能解释为什么我的工作不行吗? – dmorgan20