ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Combobox default text (https://www.excelbanter.com/excel-programming/421655-combobox-default-text.html)

joeeng

Combobox default text
 
When the text property of a combobox is filled with for instance "Select an
Item", this is what displays when the form is opened. After a selection is
made from the drop-down, the selected item is displayed in the combobox. Is
there a way to clear the selection and reset the comobox display to the
default "Select an Item" after a selection has been made?

Jim Rech

Combobox default text
 
If you immediately negate the users' selection they will not be able to see
what they picked. It would be better to reset the combo after they do
something else, like click a "commit" button. You'd use code like
ComboBox1.ListIndex = 0 to do that.

--
Jim
"joeeng" wrote in message
...
| When the text property of a combobox is filled with for instance "Select
an
| Item", this is what displays when the form is opened. After a selection
is
| made from the drop-down, the selected item is displayed in the combobox.
Is
| there a way to clear the selection and reset the comobox display to the
| default "Select an Item" after a selection has been made?


gsfeng

Combobox default text
 


"joeeng" wrote:

When the text property of a combobox is filled with for instance "Select an
Item", this is what displays when the form is opened. After a selection is
made from the drop-down, the selected item is displayed in the combobox. Is
there a way to clear the selection and reset the comobox display to the
default "Select an Item" after a selection has been made?


JLGWhiz

Combobox default text
 
You can add to the code you currently use in the Click or Change event that
does something with the user's selection as illustrated below. I used the
Change event but it will work in any of the event codes.

Private Sub ComboBox1_Change()
'Put code to execute on user selection here
chg = MsgBox("Click OK to reset ComboBox")
If chg = vbOK Then
ComboBox1.ListIndex = 0
End If
End Sub

The message box forces the user to click the OK button to reset the combo
box, since the only options on this type message box is OK or the big X close
icon. To be safe you could even include the X in the If statement:

If chg = vbOK Or chg = 1 Then
ComboBox1.ListIndex = 0
End If

The "1" is the value clicking the big X close.

"joeeng" wrote:

When the text property of a combobox is filled with for instance "Select an
Item", this is what displays when the form is opened. After a selection is
made from the drop-down, the selected item is displayed in the combobox. Is
there a way to clear the selection and reset the comobox display to the
default "Select an Item" after a selection has been made?



All times are GMT +1. The time now is 10:05 AM.

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