我的问题是,在VBA中,我无法阻止用户在输入不正确的值后离开文本框。我已经尝试过.SetFocus,但是它仍然允许在输入不正确的值后离开。
有谁有解决这个问题的办法吗?
这是我目前所拥有的:
Private Sub txtTimeOfDelivery_Exit(Cancel As Integer)
Select Case comboDriverID.Value
Case "1"
If txtTimeOfDelivery < "17:00:00" Or txtTimeOfDelivery > "22:00:00" Then
MsgBox "Warning, the selected delivery time is not within Johns working hours"
txtTimeOfDelivery.SetFocus
Else
Exit Sub
End If
Case "2"
If txtTimeOfDelivery < "17:00:00" Or txtTimeOfDelivery > "22:00:00" Then
MsgBox "Warning, the selected delivery time is not within Harrys working hours"
txtTimeOfDelivery.SetFocus
Else
Exit Sub
End If
Case "3"
If txtTimeOfDelivery < "17:00:00" Or txtTimeOfDelivery > "22:00:00" Then
MsgBox "Warning, the selected delivery time is not within Shaws working hours"
txtTimeOfDelivery.SetFocus
Else
Exit Sub
End If
Case "4"
If txtTimeOfDelivery < "17:00:00" Or txtTimeOfDelivery > "22:00:00" Then
MsgBox "Warning, the selected delivery time is not within Patricks working hours"
txtTimeOfDelivery.SetFocus
Else
Exit Sub
End If
Case "5"
If txtTimeOfDelivery < "17:00:00" Or txtTimeOfDelivery > "22:00:00" Then
MsgBox "Warning, the selected delivery time is not within Pauls working hours"
txtTimeOfDelivery.SetFocus
Else
Exit Sub
End If
Case Else
If txtTimeOfDelivery < "17:00:00" Or txtTimeOfDelivery > "22:00:00" Then
MsgBox "Please carefully check the drivers working hours"
txtTimeOfDelivery.SetFocus
Else
Exit Sub
End If
End Select
我可能想补充说,这段代码都工作正常,唯一的问题是,它允许您在输入不正确的值后离开文本框
https://stackoverflow.com/questions/20176443
复制相似问题