0

I have a drop down select list in a VBA form I would like to validate as soon the user clicks on it. It needs to check that a pre-requisite drop down has been filled already.

This is to avoid the user jumping ahead on the form because there are certain fields that need to be filled out first. My attempt so far is not working:

Private Sub cbo_moduleName_Click() If Len(cbo_moduleCode.Value) = 0 Then MsgBox ("Please select a module code") Exit Sub End If End Sub 
5
  • What is cbo_moduleCode on your UserForm? What error message you getting? Can you provide a screenshot of your UserFrom? Commented Oct 27, 2012 at 11:31
  • Oops my bad. I had posted an answer for you but then realized I was using VB6, not VBA. Commented Oct 27, 2012 at 11:36
  • @Boann your answer is correct, in vba the only diff is the event is named cbo_moduleName_Enter not cbo_moduleName_GotFocus() Commented Oct 27, 2012 at 11:37
  • @brettdj cbo_moduleCode is a dropdown menu in my form. Here is a picture i46.tinypic.com/okwwut.png Commented Oct 27, 2012 at 11:40
  • @AlexK Er I'll undelete it then, but Excel is crashing when I try it so I dunnoo. Commented Oct 27, 2012 at 11:40

1 Answer 1

2

It seems the Click event is activated only when the box's value is changed with the mouse, not every time it is physically clicked on. Try this:

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 
Sign up to request clarification or add additional context in comments.

1 Comment

Works fantasically. Thank you very much!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.