validationVBA下拉单击

我有一个VBA表单下拉select列表,我想在用户点击它的时候立即进行validation。 它需要检查一个先决条件下拉已经填满。

这是为了避免用户在表单上跳跃,因为有些字段需要先填写。 我到目前为止的尝试不工作:

Private Sub cbo_moduleName_Click() If Len(cbo_moduleCode.Value) = 0 Then MsgBox ("Please select a module code") Exit Sub End If End Sub 

看来Click事件只有在用鼠标改变框的值时才会被激活,而不是每次物理点击都被激活。 尝试这个:

 Private Sub cbo_moduleName_Enter() If Len(cbo_moduleCode.Value) = 0 Then MsgBox ("Please select a module code") cbo_moduleCode.SetFocus Exit Sub End If End Sub