在用户移动到用户表单上的下一个字段之前,我需要检查文本框是否为空/空或空白。这是检查文本框是否为空/null/空白的代码。我的问题是它不会将焦点返回到文本框,而是移动到用户表单中的下一个字段。
Private Sub txtTDYLocation_lostfocus()
Dim Pcase As String
'converts text to proper case
If Trim(txtTDYLocation.Value & "") = "" Then
MsgBox "Please enter TDY location", vbOKOnly
txtTDYLocation.SetFocus
Else
Pcase = Me.txtTDYLocation
Pcase = StrConv(Pcase, vbProperCase)
Me.txtTDYLocation.Text = Pcase
Me.txtTDYLocation = StrConv(Me.txtTDYLocation, 3)
End If
End Sub
为此,您应该使用该事件txtTDYLocation_BeforeUpdate
如果值为Null在文本框中。一旦取消设置为True焦点将无法离开文本框。
Private Sub txtTDYLocation_BeforeUpdate(Cancel As Integer)
If Trim(txtTDYLocation & "") = "" Then
MsgBox "Please enter TDY location", vbOKOnly
Cancel = True
End If
End Sub
And in txtTDYLocation_AfterUpdate()
您可以更改该值。
Private Sub txtTDYLocation_AfterUpdate()
Dim Pcase As String
'converts text to proper case
If Trim(txtTDYLocation.Value & "") <> "" Then
Pcase = Me.txtTDYLocation
Pcase = StrConv(Pcase, vbProperCase)
Me.txtTDYLocation.Value = Pcase
Me.txtTDYLocation = StrConv(Me.txtTDYLocation, 3)
End If
End Sub
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)