VB如何设置TEXT内容不能为空

如题 我要的是代码

第1个回答  2013-11-17
主要是在焦点切换时 来验证
Dim tState As Boolean '开关

Private Sub Text1_GotFocus()'获取焦点时
tState = True
End Sub

Private Sub Text2_GotFocus()'获取焦点时
tState = True
End Sub

Private Sub Text1_LostFocus()'失去焦点时
If Text1.Text = "" And tState Then
MsgBox "该项不能为空"
Text1.SetFocus
End If
tState = False
End Sub

Private Sub Text2_LostFocus()
If Text2.Text = "" And tState Then
MsgBox "该项不能为空"
Text2.SetFocus
End If
tState = False
End Sub
第2个回答  推荐于2018-05-09
Private Sub Timer1_Timer()
if me.TEXT1.text="" then
msgbox "TEXT内容不能为空",,"wrong"
me.text1.text="TEXT内容不能为空"
End if
End Sub本回答被网友采纳
第3个回答  2013-11-17
Private Sub Command1_Click()
If (Text1.Text = "") Then
MsgBox "内容不能为空"
End If
End Sub本回答被网友采纳
第4个回答  2013-11-17
文本框有自己的验证事件,代码如下。
Private Sub Text1_Validate(Cancel As Boolean)
If Text1.Text = "" Then
MsgBox "空"
Cancel = True
End If
End Sub