Help with SetFocus required please

J

Jim

I have a combobox in a userform and wish to prevent the leaving the value
blank.
I have used the following code

If ComboBox1.listIndex = -1 Then
Msgbox "Please select a value"
Combobox1.SetFocus
End If

It doesn't work - the focus moves to the next control

Why is this ?
 
J

Jim

I should have specified that I have used the code in the Exit Procedure as
follows

Private Sub ComboBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)

If ComboBox1.listIndex = -1 Then
Msgbox "Please select a value"
ComboBox1.SetFocus
End If

End Sub


Regards & TIA
 
R

Rick Rothstein \(MVP - VB\)

Instead of ComboBox1.SetFocus, try using Cancel = True instead.

Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top