Combobox default text

J

joeeng

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?
 
J

Jim Rech

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
| 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?
 
G

gsfeng

joeeng said:
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?
 
J

JLGWhiz

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.
 

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