ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   ComboBox Problem (https://www.excelbanter.com/excel-programming/305832-combobox-problem.html)

R Avery

ComboBox Problem
 
I have a form that on loading Sets Focus to the only combobox on the
form. THe combobox initially starts out either blank or with text, and
always has the same list of values.

However, when the combox box starts out empty, there is no cursor inside
of it so I can't just start typing text. How do I fix this?

Tom Ogilvy

ComboBox Problem
 
I put a combobox on a userform with several controls. The combobox had no
data in the list. I set the TabIndex property to 0 and when I showed the
form, the cursor was blinking in the combobox. If you are using some other
method, don't.

--
Regards,
Tom Ogilvy

"R Avery" wrote in message
...
I have a form that on loading Sets Focus to the only combobox on the
form. THe combobox initially starts out either blank or with text, and
always has the same list of values.

However, when the combox box starts out empty, there is no cursor inside
of it so I can't just start typing text. How do I fix this?




R Avery

ComboBox Problem
 
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?

Tom Ogilvy

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?




R Avery

ComboBox Problem
 
I tried something similar to this before, and it did not work. However,
this code does work. I'm not sure why my code didn't work, but thanks
so much, Tom! This form now works great.


Tom Ogilvy wrote:

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.



All times are GMT +1. The time now is 01:27 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com