首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何阻止用户离开文本框

如何阻止用户离开文本框
EN

Stack Overflow用户
提问于 2013-11-24 23:45:01
回答 1查看 3.8K关注 0票数 1

我的问题是,在VBA中,我无法阻止用户在输入不正确的值后离开文本框。我已经尝试过.SetFocus,但是它仍然允许在输入不正确的值后离开。

有谁有解决这个问题的办法吗?

这是我目前所拥有的:

代码语言:javascript
复制
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

我可能想补充说,这段代码都工作正常,唯一的问题是,它允许您在输入不正确的值后离开文本框

EN

回答 1

Stack Overflow用户

发布于 2013-11-24 23:49:11

在LostFocus事件中,如果值不正确,您可以将焦点重新设置到文本框上吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20176443

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档