我在一次验证三个下拉菜单时遇到问题。以下是测试用例:
cbo_fac1 - user must select this as a pre-requisite for cbo_fac1 and cbo_fac2
cbo_fac2 - user must select cbo_fac1 as a pre-requisite
cbo_fac3 - user must select cbo_fac1 and cbo_fac2 as a pre-requisite
这是我到目前为止使用的代码。不幸的是,在某些情况下,即如果用户首先尝试选择cbo_fac3,它似乎会循环一些错误。有什么方法可以合并这些函数并让它在每种情况下只显示一次错误?
Private Sub cbo_fac2_Enter()
If Len(cbo_fac1.Value) = 0 Then
MsgBox ("Please select a first preference before selecting a second preference")
cbo_fac1.SetFocus
Exit Sub
End If
End Sub
Private Sub cbo_fac3_Enter()
If Len(cbo_fac2.Value) = 0 & Len(cbo_fac3.Value) = 0 Then
MsgBox ("Please select a first preference before selecting a second/third preference")
cbo_fac1.SetFocus
Exit Sub
End If
If Len(cbo_fac2.Value) = 0 Then
MsgBox ("Please select a second preference before selecting a third preference")
cbo_fac2.SetFocus
Exit Sub
End If
End Sub