combobox setfocus

S

slarbie

I have a validation routine built for the exit event of my combobox, and it
all works fine. But I'd like the cursor to be blinking in the box again when
all's said and done so the user doesn't have to click back on the control. I
thought the SetFocus, SelStart and SelLength would do that, but no such luck
with the way I have it written. I've also tried various combinations of 1's
and 0's for the SelStart and SelLength settings. What am I missing?

Private Sub cboRPI_Exit(ByVal Cancel As MSForms.ReturnBoolean)

If cboRPI <> "" And cboChassis = "blahblah" Then
n = Val(cboRPI)

If n Mod 50 <> 0 Or n < 50 Or n > 7500 Then
Cancel = True
MsgBox "Must be in $50 increments between $50 and $7,500"
cboRPI = ""
cboRPI.SelLength = 0
cboRPI.SelStart = 0
cboRPI.SetFocus
End If

End If

End Sub
 
D

Dave Peterson

The cancel will keep the focus in the textbox, so you don't need to use
..setfocus.

And this seemed to work fine for me:

If n Mod 50 <> 0 Or n < 50 Or n > 7500 Then
Cancel = True
MsgBox "Must be in $50 increments between $50 and $7,500"
cboRPI = ""
End If

=====
Personally, I think a label that would hold the error message is nicer than a
msgbox, but that's not part of your question.
 
S

slarbie

Thanks Dave, I appreciate the quick response. That didn't work for me either
- but it helps just to know that it did work for you. Makes me think my
problem might instead be due to there being no items in the combobox list.
I'll go and try just creating a single "" item. I know I know - why am I
using a combobox for this? Long story, but there really is a reason for it -
I won't bore you with the details - most of the time it actually has list
items...
 
D

Dave Peterson

I tried it again with no items in the combobox list (I used .clear to clear it).

And it still worked ok. I was left with a flashing I-beam cursor in the
combobox input area.

ps.

I used xl2003 for my tests.
 

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