Hi,
In my Excel application, I need a control that would allow both to select a value from an existing list and to enter a value from a keybord that is *not* in the list. Initially, I had the ComboBox just for selection from the list and new values were entered into an Excel's cell, but it was too confusing to users who are forced to address a single article in two different places, so I'm searching for a way to merge both functions. To monitor selection from the list, I use ComboBox_Change event, but it also reacts to every keypress as if the single letter or a first existing value that starts with that letter was a right value to process. I'd like to separate ComboBox' reaction to keyboard from full-fledged values' selection from the list.
As a trial, I used the following code:
It *almost* worked... until I found that pressing Delete or Backspace (the latter - contrary to what the online help claims) doesn't tip KeyPress event, so when I fix the value with these, Change is invoked in full. Is there a way to filter them out somehow?
On the other hand, I've been considering other alternatives to emulate the work of such a smart Combo in case a real one isn't possible. For example, I tried to use a simple TextBox to work with the keyboard, almost overlapping the body of a ComboBox except its dropdown button. But when I click on the ComboBox, it's brought forward in Z-order, covering the TextBox completely. And when I try to use ZOrder method to restore TextBox' position, the compiler throws an "Invalid use of property" error. Trying to use ZOrder as a property doesn't work either.
Another possibility would be to decrease the width of the ComboBox, so that only its dropdown button would be visible, and with the TextBox at its left side they both would create an illusion of a single normal-sized ComboBox. That works almost alright, but the dropdown list of the Combo would be appearing to the right from it (if I modify its width for a sensible size, that is) rather than below as if it was belonging to a normal ComboBox. Is it possible to align the dropdown box to the right edge of the Combo body?
Thanks.
In my Excel application, I need a control that would allow both to select a value from an existing list and to enter a value from a keybord that is *not* in the list. Initially, I had the ComboBox just for selection from the list and new values were entered into an Excel's cell, but it was too confusing to users who are forced to address a single article in two different places, so I'm searching for a way to merge both functions. To monitor selection from the list, I use ComboBox_Change event, but it also reacts to every keypress as if the single letter or a first existing value that starts with that letter was a right value to process. I'd like to separate ComboBox' reaction to keyboard from full-fledged values' selection from the list.
As a trial, I used the following code:
Code:
Dim KeyPr as Integer
Private Sub MyCombo_KeyPress(ByVal KeyANSI As MSForms.ReturnInteger)
KeyPr = 1
End Sub
Private Sub MyCombo_Change()
If KeyPr = 1 Then
KeyPr = 0
Exit Sub
End If
KeyPr = 0
(operational code)
End Sub
On the other hand, I've been considering other alternatives to emulate the work of such a smart Combo in case a real one isn't possible. For example, I tried to use a simple TextBox to work with the keyboard, almost overlapping the body of a ComboBox except its dropdown button. But when I click on the ComboBox, it's brought forward in Z-order, covering the TextBox completely. And when I try to use ZOrder method to restore TextBox' position, the compiler throws an "Invalid use of property" error. Trying to use ZOrder as a property doesn't work either.
Another possibility would be to decrease the width of the ComboBox, so that only its dropdown button would be visible, and with the TextBox at its left side they both would create an illusion of a single normal-sized ComboBox. That works almost alright, but the dropdown list of the Combo would be appearing to the right from it (if I modify its width for a sensible size, that is) rather than below as if it was belonging to a normal ComboBox. Is it possible to align the dropdown box to the right edge of the Combo body?
Thanks.