0
我有一個問題一次驗證三個下拉列表。這裏是測試用例:防止驗證錯誤發生的雙重實例
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