View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default ComboBox Problem

Private Sub Userform_Activate()
ComboBox1.SetFocus
If ComboBox1.Text = "" Then
ComboBox1.SelStart = 0
Else
ComboBox1.SelStart = 0
ComboBox1.SelLength = Len(ComboBox1.Text)
End If
End Sub


is a possibility. Worked for me with hiding the form.

--
Regards,
Tom Ogilvy

"R Avery" wrote in message
...
I figured out the problem, but it sure took a while. I tried your
suggestion, and it worked, for the first time only. Any subsequent
.Show's of the form did not have the cursor in the combobox. However,
when I tried to replicate my experience in a new simple form, I got the
same behavior.

I solved this for the simple form by doing an Unload Form1 before
showing the form each time, and it worked perfectly. However, that did
not work for my form.

It turns out that I had disabled the form QueryClose event by always
setting the Cancel parameter to TRUE. After removing that code, the
form was properly unloaded from memory, and when shown again, the cursor
is properly inside the combobox.

However, suppose in the future, I desire the capability to select a
ComboBox programmatically and select all text inside (or put the cursor
inside, if no item has been chosen). How would one do that?