[英]onLost focus Event is not working -ms access
This code is not working. 此代码无效。 Can anyone help me out?
谁能帮我吗?
Private Sub txtErrorComment_5_LostFocus()
If IsEmpty(Me.txtErrorComment_5) Then
MsgBox "Eh..! It cannot be Empty."
End If
End Sub
txtErrorComment_5 is probably Null - which evaluates to False when run through IsEmpty() - yes, this is un-intuitive, but whenever you compare to Null, the result is false. txtErrorComment_5可能为Null-通过IsEmpty()运行时其值为False-是的,这是不直观的,但是每当与Null比较时,结果均为false。
Try the following: 请尝试以下方法:
Private Sub txtErrorComment_5_LostFocus()
If IsEmpty(Me.txtErrorComment_5) or IsNull(Me.txtErrorComment_5) Then
MsgBox "Eh..! It cannot be Empty."
End If
End Sub
Or just: 要不就:
Private Sub txtErrorComment_5_LostFocus()
If IsNull(Me.txtErrorComment_5) Then
MsgBox "Eh..! It cannot be Empty."
End If
End Sub
IsNull can handle Null's IsNull可以处理Null
Edit: 编辑:
@David-W-Fenton is correct. @ David-W-Fenton是对的。 The better way to do this BeforeUpdate (not LostFocus)
更好的方法是使用BeforeUpdate(不是LostFocus)
Private Sub txtErrorComment_5_BeforeUpdate(Cancel As Integer)
If IsNull(Me.txtErrorComment_5) Then
MsgBox "Eh..! It cannot be Empty."
Cancel=true
End If
End Sub
To detect whether txtErrorComment_5 is blank, concatenate a Null string to its value and see whether the character length of the combined expression is zero. 若要检测txtErrorComment_5是否为空,请将Null字符串连接为其值,并查看组合表达式的字符长度是否为零。
Private Sub txtErrorComment_5_LostFocus()
If Len(Me.txtErrorComment_5 & vbNullString) = 0 Then
MsgBox "Eh..! It cannot be Empty."
End If
End Sub
If you want txtErrorComment_5 treated as blank when it contains only one or more space characters, include the Trim() function. 如果您希望txtErrorComment_5在仅包含一个或多个空格字符时视为空白,请包含Trim()函数。
Private Sub txtErrorComment_5_LostFocus()
If Len(Trim(Me.txtErrorComment_5) & vbNullString) = 0 Then
MsgBox "Eh..! It cannot be Empty."
End If
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.