两个文本框,TABINDEX属性分别为1和2,以下语句,为防止出现空值,可是当TEXT1获得焦
点时如果不输入任何值按TAB键,后将出现死循环,可是我就是想实现当TEXT1为空时
TEXT1获得焦点而不把焦点转移到下一个控件怎么办呢?
Private Sub Text1_LostFocus()
If Text1.Text = "" Then
MsgBox "text1不能为空!"
Text1.SetFocus
End If
End SubPrivate Sub Text2_LostFocus()
If Text2.Text = "" Then
MsgBox "text2不能为空!"
Text2.SetFocus
End If
End Sub
点时如果不输入任何值按TAB键,后将出现死循环,可是我就是想实现当TEXT1为空时
TEXT1获得焦点而不把焦点转移到下一个控件怎么办呢?
Private Sub Text1_LostFocus()
If Text1.Text = "" Then
MsgBox "text1不能为空!"
Text1.SetFocus
End If
End SubPrivate Sub Text2_LostFocus()
If Text2.Text = "" Then
MsgBox "text2不能为空!"
Text2.SetFocus
End If
End Sub
If Text1.Text = "" Then Cancel = True
End Sub
private mbErr as booleanPrivate Sub Text1_LostFocus()
if mberr then exit sub
If Text1.Text = "" Then
mberr = true
MsgBox "text1不能为空!"
Text1.SetFocus
else
mberr = false
End If
End SubPrivate Sub Text2_LostFocus()
if mberr then exit sub
If Text2.Text = "" Then
mberr = true
MsgBox "text2不能为空!"
Text2.SetFocus
else
mberr = false
End IfEnd Sub
If Text1.Text = "" and not text2.text="" Then
MsgBox "text1不能为空!"
Text1.SetFocus
End If
End SubPrivate Sub Text2_LostFocus()
If Text2.Text = "" and not text1.text="" Then
MsgBox "text2不能为空!"
Text2.SetFocus
End If
End Sub
华军软件 http://www.onlinedown.net/soft/7545.htm
If Text1.Text = "" Then Cancel = True
End Sub
If Text1.Text = "" Then
MsgBox "text不可以为空"
End If
Text1.SetFocus
End Sub
就这样也可以啊
If Text1.Text = "" Then Cancel = True
End Sub
'OK啦。